Create streams from ECMAScript® 2015 Iterators.
npm install stream-from-iterator --save
import StreamFromIterator from 'stream-from-iterator';
function * strRange(start, end) {
for (var i = start; i <= end; i++) {
yield String(i);
}
}
new StreamFromIterator(strRange(0, 9))
.pipe(process.stdout); // output: 0123456789
import StreamFromIterator from 'stream-from-iterator';
new StreamFromIterator(['some', ' ', 'strings'].values())
.pipe(process.stdout); // output: some strings
new StreamFromIterator([new Buffer('some'), ' mixed ', new Buffer('strings')].values())
.pipe(process.stdout); // output: some mixed strings
import StreamFromIterator from 'stream-from-iterator';
var i = 0;
StreamFromIterator.obj(['some', 42, 'mixed', 'array', () => {}].values())
.on('data', data => {
console.log(i++ + ': ' + typeof data);
/* outputs:
0: string
1: number
2: string
3: string
4: function
*/
});
StreamFromIterators are Readable streams.
- iterator
Iterator
ES2015 Iterator iterating over arbitrary Javascript values like numbers, strings, objects, functions, ... - options
Object
passed through new Readable([options])
Note: The new
operator can be omitted.
A convenience wrapper for new StreamFromIterator(iterator, {objectMode: true, ...})
.
- stream-from: Create streams from promises, iterators, factories and arbitrary Javascript values like functions, arrays, etc.
MIT © Michael Mayer