Skip to content

Commit 580401b

Browse files
authored
Merge pull request #1 from fluture-js/avaq/everything
Add everything
2 parents 1802113 + f06fce8 commit 580401b

File tree

14 files changed

+302
-0
lines changed

14 files changed

+302
-0
lines changed

.config

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,5 @@
1+
author-name = Aldwin Vlasblom
2+
repo-owner = fluture-js
3+
repo-name = fluture-node
4+
source-files = index.mjs
5+
opening-delimiter = ```js

.eslintrc.json

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
{
2+
"root": true,
3+
"extends": ["./node_modules/sanctuary-style/eslint-es6.json"],
4+
"overrides": [
5+
{
6+
"files": ["README.md"],
7+
"globals": {
8+
"EventEmitter": "readonly",
9+
"Future": "readonly",
10+
"Readable": "readonly",
11+
"buffer": "readonly",
12+
"once": "readonly"
13+
}
14+
}
15+
]
16+
}

.gitignore

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
/coverage/
2+
/index.js
3+
/node_modules/

.npmrc

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
package-lock=false

.travis.yml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
language: node_js
2+
node_js:
3+
- "11"
4+
after_success: npm run codecov

CONTRIBUTING.md

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
# Contribution Guideline
2+
3+
## Making a contribution
4+
5+
1. Fork the repo if you do not have write access
6+
1. Clone the remote (fork) from GitHub
7+
1. Create a branch named `<yourgithubusername>/<yourfeature>`
8+
1. Make one or more atomic commits
9+
1. Make sure the tests pass locally
10+
1. Create a pull-request on GitHub
11+
12+
## Publishing a new version
13+
14+
1. Make sure you have write access to the module on npm
15+
1. Make sure you have write access to the master branch on GitHub
16+
1. Checkout `master` and make sure it's up to date with the remote
17+
1. Run `npm run release <level>`, where `<level>` can be any of: 'major',
18+
'minor', 'patch', 'premajor', 'preminor', 'prepatch', or 'prerelease'.

LICENSE

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
The MIT License (MIT)
2+
Copyright (c) 2019 Aldwin Vlasblom
3+
4+
Permission is hereby granted, free of charge, to any person obtaining a copy of
5+
this software and associated documentation files (the "Software"), to deal in
6+
the Software without restriction, including without limitation the rights to
7+
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
8+
of the Software, and to permit persons to whom the Software is furnished to do
9+
so, subject to the following conditions:
10+
11+
The above copyright notice and this permission notice shall be included in all
12+
copies or substantial portions of the Software.
13+
14+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
SOFTWARE.

index.mjs

Lines changed: 80 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,80 @@
1+
//. # Fluture Node
2+
//.
3+
//. Common Node API's wrapped to return [Fluture][] Futures.
4+
//.
5+
//. ## API
6+
7+
import Future from 'fluture';
8+
9+
//# once :: String -> EventEmitter -> Future Error a
10+
//.
11+
//. Resolve a Future with the first event emitted over
12+
//. the given event emitter under the given event name.
13+
//.
14+
//. When the Future is cancelled, it removes any trace of
15+
//. itself from the event emitter.
16+
//.
17+
//. ```js
18+
//. > const emitter = new EventEmitter ();
19+
//. > setTimeout (() => emitter.emit ('answer', 42), 100);
20+
//. > once ('answer') (emitter);
21+
//. Future.of (42);
22+
//. ```
23+
export const once = event => emitter => Future ((rej, res) => {
24+
const removeListeners = () => {
25+
emitter.removeListener ('error', onError);
26+
emitter.removeListener (event, onEvent);
27+
};
28+
const onError = x => {
29+
removeListeners ();
30+
rej (x);
31+
};
32+
const onEvent = x => {
33+
removeListeners ();
34+
res (x);
35+
};
36+
emitter.once ('error', onError);
37+
emitter.once (event, onEvent);
38+
return removeListeners;
39+
});
40+
41+
//# buffer :: ReadableStream a -> Future Error (Array a)
42+
//.
43+
//. Buffer all data on a Stream into a Future of an Array.
44+
//.
45+
//. When the Future is cancelled, it removes any trace of
46+
//. itself from the Stream.
47+
//.
48+
//. ```js
49+
//. > const stream = new Readable ({read: () => {}});
50+
//. > setTimeout (() => {
51+
//. . stream.push ('hello');
52+
//. . stream.push ('world');
53+
//. . stream.push (null);
54+
//. . }, 100);
55+
//. > buffer (stream);
56+
//. Future.of ([Buffer.from ('hello'), Buffer.from ('world')]);
57+
//. ```
58+
export const buffer = stream => Future ((rej, res) => {
59+
const chunks = [];
60+
const removeListeners = () => {
61+
stream.removeListener ('data', onData);
62+
stream.removeListener ('error', rej);
63+
stream.removeListener ('end', onEnd);
64+
};
65+
const onData = d => chunks.push (d);
66+
const onEnd = () => {
67+
removeListeners ();
68+
res (chunks);
69+
};
70+
const onError = e => {
71+
removeListeners ();
72+
rej (e);
73+
};
74+
stream.on ('data', onData);
75+
stream.once ('error', onError);
76+
stream.once ('end', onEnd);
77+
return removeListeners;
78+
});
79+
80+
//. [Fluture]: https://github.com/fluture-js/Fluture

package.json

Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
{
2+
"name": "fluture-node",
3+
"version": "0.0.0",
4+
"description": "Common Node API's wrapped to return Fluture Futures",
5+
"main": "index",
6+
"module": "index.mjs",
7+
"scripts": {
8+
"build": "rollup -c rollup.config.mjs",
9+
"codecov": "codecov",
10+
"doctest": "sanctuary-doctest",
11+
"lint": "sanctuary-lint",
12+
"release": "sanctuary-release",
13+
"test": "npm run lint && sanctuary-test && npm run doctest"
14+
},
15+
"repository": {
16+
"type": "git",
17+
"url": "git://github.com/fluture-js/fluture-node.git"
18+
},
19+
"files": [
20+
"/index.js",
21+
"/index.mjs",
22+
"/LICENSE",
23+
"/package.json",
24+
"/README.md"
25+
],
26+
"author": "Aldwin Vlasblom <aldwin@avaq.it> (https://github.com/Avaq)",
27+
"license": "MIT",
28+
"dependencies": {},
29+
"peerDependencies": {
30+
"fluture": "*"
31+
},
32+
"devDependencies": {
33+
"c8": "^3.4.0",
34+
"codecov": "^3.2.0",
35+
"fluture": "^11.0.1",
36+
"oletus": "^1.1.5",
37+
"rollup": "^1.1.2",
38+
"sanctuary-scripts": "^3.1.1"
39+
}
40+
}

rollup.config.mjs

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
export default {
2+
input: 'index.mjs',
3+
external: ['fluture'],
4+
output: {
5+
format: 'cjs',
6+
file: 'index.js',
7+
interop: false,
8+
},
9+
};

0 commit comments

Comments
 (0)