Skip to content

Commit ab0d2c9

Browse files
committed
initial commit
0 parents  commit ab0d2c9

File tree

11 files changed

+4752
-0
lines changed

11 files changed

+4752
-0
lines changed

.babelrc.js

Lines changed: 47 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,47 @@
1+
'use strict'
2+
3+
const NODE_ENV = process.env.NODE_ENV || 'development'
4+
const __PROD__ = NODE_ENV === 'production'
5+
const __TEST__ = NODE_ENV === 'test'
6+
7+
const pkg = require('./package')
8+
9+
const plugins = {
10+
lodash: {},
11+
}
12+
13+
const presets = {
14+
'@babel/preset-env': {
15+
debug: !__TEST__,
16+
loose: true,
17+
shippedProposals: true,
18+
targets: __PROD__
19+
? (() => {
20+
let node = (pkg.engines || {}).node
21+
if (node !== undefined) {
22+
const trimChars = '^=>~'
23+
while (trimChars.includes(node[0])) {
24+
node = node.slice(1)
25+
}
26+
return { node: node }
27+
}
28+
})()
29+
: { browsers: '', node: 'current' },
30+
useBuiltIns: '@babel/polyfill' in (pkg.dependencies || {}) && 'usage',
31+
},
32+
}
33+
34+
Object.keys(pkg.devDependencies || {}).forEach(name => {
35+
if (!(name in presets) && /@babel\/plugin-.+/.test(name)) {
36+
plugins[name] = {}
37+
} else if (!(name in presets) && /@babel\/preset-.+/.test(name)) {
38+
presets[name] = {}
39+
}
40+
})
41+
42+
module.exports = {
43+
comments: !__PROD__,
44+
ignore: __TEST__ ? undefined : [/\.spec\.js$/],
45+
plugins: Object.keys(plugins).map(plugin => [plugin, plugins[plugin]]),
46+
presets: Object.keys(presets).map(preset => [preset, presets[preset]]),
47+
}

.editorconfig

Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
# http://EditorConfig.org
2+
#
3+
# Julien Fontanet's configuration
4+
# https://gist.github.com/julien-f/8096213
5+
6+
# Top-most EditorConfig file.
7+
root = true
8+
9+
# Common config.
10+
[*]
11+
charset = utf-8
12+
end_of_line = lf
13+
insert_final_newline = true
14+
trim_trailing_whitespace = true
15+
16+
# CoffeeScript
17+
#
18+
# https://github.com/polarmobile/coffeescript-style-guide/blob/master/README.md
19+
[*.{,lit}coffee]
20+
indent_size = 2
21+
indent_style = space
22+
23+
# Markdown
24+
[*.{md,mdwn,mdown,markdown}]
25+
indent_size = 4
26+
indent_style = space
27+
trim_trailing_whitespace = false
28+
29+
# Package.json
30+
#
31+
# This indentation style is the one used by npm.
32+
[package.json]
33+
indent_size = 2
34+
indent_style = space
35+
36+
# Pug (Jade)
37+
[*.{jade,pug}]
38+
indent_size = 2
39+
indent_style = space
40+
41+
# JavaScript
42+
#
43+
# Two spaces seems to be the standard most common style, at least in
44+
# Node.js (http://nodeguide.com/style.html#tabs-vs-spaces).
45+
[*.{js,jsx,ts,tsx}]
46+
indent_size = 2
47+
indent_style = space
48+
49+
# Less
50+
[*.less]
51+
indent_size = 2
52+
indent_style = space
53+
54+
# Sass
55+
#
56+
# Style used for http://libsass.com
57+
[*.s[ac]ss]
58+
indent_size = 2
59+
indent_style = space
60+
61+
# YAML
62+
#
63+
# Only spaces are allowed.
64+
[*.yaml]
65+
indent_size = 2
66+
indent_style = space

.eslintrc.js

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
module.exports = {
2+
extends: ['standard'],
3+
parser: 'babel-eslint',
4+
rules: {
5+
'comma-dangle': ['error', 'always-multiline'],
6+
'no-var': 'error',
7+
'node/no-extraneous-import': 'error',
8+
'node/no-extraneous-require': 'error',
9+
'node/no-missing-require': 'error',
10+
'node/no-missing-import': 'error',
11+
'prefer-const': 'error',
12+
},
13+
}

.flowconfig

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,13 @@
1+
[ignore]
2+
3+
[include]
4+
5+
[libs]
6+
7+
[lints]
8+
9+
[options]
10+
include_warnings=true
11+
module.use_strict=true
12+
13+
[strict]

.gitignore

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
/coverage/
2+
/dist/
3+
/node_modules/
4+
5+
npm-debug.log
6+
npm-debug.log.*
7+
pnpm-debug.log
8+
pnpm-debug.log.*
9+
yarn-error.log

.npmignore

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
/benchmark/
2+
/benchmarks/
3+
*.bench.js
4+
*.bench.js.map
5+
6+
/examples/
7+
example.js
8+
example.js.map
9+
*.example.js
10+
*.example.js.map
11+
12+
/fixture/
13+
/fixtures/
14+
*.fixture.js
15+
*.fixture.js.map
16+
*.fixtures.js
17+
*.fixtures.js.map
18+
19+
/test/
20+
/tests/
21+
*.spec.js
22+
*.spec.js.map
23+
24+
__snapshots__/

.travis.yml

Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
language: node_js
2+
node_js:
3+
- stable
4+
- 8
5+
- 6
6+
- 4
7+
8+
# Use containers.
9+
# http://docs.travis-ci.com/user/workers/container-based-infrastructure/
10+
sudo: false

README.md

Lines changed: 109 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,109 @@
1+
# async-iterator-to-stream [![Build Status](https://travis-ci.org/JsCommunity/async-iterator-to-stream.png?branch=master)](https://travis-ci.org/JsCommunity/async-iterator-to-stream)
2+
3+
> Convert an async iterator/iterable to a readable stream
4+
5+
Even though this library is dedicated to async iterators, it is fully
6+
compatible with synchronous ones.
7+
8+
Furthermore, generators can be used to create readable stream factories!
9+
10+
## Install
11+
12+
Installation of the [npm package](https://npmjs.org/package/async-iterator-to-stream):
13+
14+
```
15+
> npm install --save async-iterator-to-stream
16+
```
17+
18+
## Usage
19+
20+
```js
21+
const asyncIteratorToStream = require('async-iterator-to-stream')
22+
23+
// sync/async iterators
24+
asyncIteratorToStream(new Set(['foo', 'bar']).values())
25+
.pipe(output)
26+
27+
// sync/async iterables
28+
asyncIteratorToStream.obj([1, 2, 3])
29+
.pipe(output)
30+
31+
// if you pass a sync/async generator, it will return a factory instead of a
32+
// stream
33+
const createRangeStream = asyncIteratorToStream.obj(function * (n) {
34+
for (let i = 0; i < n; ++i) {
35+
yield i
36+
}
37+
})
38+
createRangeStream(10)
39+
.pipe(output)
40+
```
41+
42+
## Example
43+
44+
Let's implement a simpler `fs.createReadStream` to illustrate the usage of this
45+
library.
46+
47+
```js
48+
const asyncIteratorToStream = require('async-iterator-to-stream')
49+
50+
// promisified fs
51+
const fs = require('mz/fs')
52+
53+
const createReadStream = asyncIteratorToStream(async function * (file) {
54+
const fd = await fs.open(file, 'r')
55+
try {
56+
let size = yield
57+
while (true) {
58+
const buf = Buffer.alloc(size)
59+
const [n] = await fs.read(fd, buf, 0, size, null)
60+
if (n < size) {
61+
yield buf.slice(0, n)
62+
return
63+
}
64+
size = yield buf
65+
}
66+
} finally {
67+
await fs.close(fd)
68+
}
69+
})
70+
71+
createReadStream('foo.txt').pipe(process.stdout)
72+
```
73+
74+
> If your environment does not support async generators, you may use a sync
75+
> generator instead and `yield` promises to wait for them.
76+
77+
## Development
78+
79+
```
80+
# Install dependencies
81+
> yarn
82+
83+
# Run the tests
84+
> yarn test
85+
86+
# Continuously compile
87+
> yarn dev
88+
89+
# Continuously run the tests
90+
> yarn dev-test
91+
92+
# Build for production
93+
> yarn build
94+
```
95+
96+
## Contributions
97+
98+
Contributions are *very* welcomed, either on the documentation or on
99+
the code.
100+
101+
You may:
102+
103+
- report any [issue](https://github.com/JsCommunity/async-iterator-to-stream/issues)
104+
you've encountered;
105+
- fork and create a pull request.
106+
107+
## License
108+
109+
ISC © [Julien Fontanet](https://github.com/julien-f)

package.json

Lines changed: 81 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,81 @@
1+
{
2+
"name": "async-iterator-to-stream",
3+
"version": "1.0.0",
4+
"license": "ISC",
5+
"description": "Convert an async iterator/iterable to a readable stream",
6+
"keywords": [
7+
"async",
8+
"generator",
9+
"iterable",
10+
"iteration",
11+
"iterator",
12+
"promise",
13+
"readable",
14+
"stream"
15+
],
16+
"homepage": "https://github.com/JsCommunity/async-iterator-to-stream",
17+
"bugs": "https://github.com/JsCommunity/async-iterator-to-stream/issues",
18+
"repository": {
19+
"type": "git",
20+
"url": "https://github.com/JsCommunity/async-iterator-to-stream.git"
21+
},
22+
"preferGlobal": false,
23+
"main": "dist/",
24+
"bin": {},
25+
"files": [
26+
"dist/"
27+
],
28+
"browserslist": [
29+
">2%"
30+
],
31+
"engines": {
32+
"node": ">=4"
33+
},
34+
"dependencies": {
35+
"@babel/runtime": "^7.0.0-beta.42",
36+
"readable-stream": "^2.3.5"
37+
},
38+
"devDependencies": {
39+
"@babel/cli": "^7.0.0-beta.42",
40+
"@babel/core": "^7.0.0-beta.42",
41+
"@babel/plugin-transform-runtime": "^7.0.0-beta.42",
42+
"@babel/preset-env": "^7.0.0-beta.42",
43+
"@babel/preset-flow": "^7.0.0-beta.42",
44+
"babel-core": "^7.0.0-bridge.0",
45+
"babel-eslint": "^8.2.2",
46+
"babel-jest": "^21",
47+
"babel-plugin-lodash": "^3.3.2",
48+
"cross-env": "^5.1.4",
49+
"eslint": "^4.19.1",
50+
"eslint-config-standard": "^11.0.0",
51+
"eslint-plugin-import": "^2.9.0",
52+
"eslint-plugin-node": "^6.0.1",
53+
"eslint-plugin-promise": "^3.7.0",
54+
"eslint-plugin-standard": "^3.0.1",
55+
"flow-bin": "^0.68.0",
56+
"husky": "^0.14.3",
57+
"jest": "^21",
58+
"rimraf": "^2.6.2"
59+
},
60+
"scripts": {
61+
"build": "cross-env NODE_ENV=production babel --source-maps --out-dir=dist/ src/",
62+
"clean": "rimraf dist/",
63+
"commitmsg": "npm test",
64+
"dev": "cross-env NODE_ENV=development babel --watch --source-maps --out-dir=dist/ src/",
65+
"dev-test": "jest --bail --watch",
66+
"posttest": "jest",
67+
"prebuild": "npm run clean",
68+
"predev": "npm run prebuild",
69+
"prepublishOnly": "npm run build",
70+
"pretest": "eslint --ignore-path .gitignore --fix .",
71+
"test": "flow status"
72+
},
73+
"jest": {
74+
"collectCoverage": true,
75+
"testEnvironment": "node",
76+
"roots": [
77+
"<rootDir>/src"
78+
],
79+
"testRegex": "\\.spec\\.js$"
80+
}
81+
}

0 commit comments

Comments
 (0)