|
|
7 роки тому | |
|---|---|---|
| tests | 7 роки тому | |
| .editorconfig | 7 роки тому | |
| .gitignore | 7 роки тому | |
| .prettierrc | 7 роки тому | |
| .travis.yml | 7 роки тому | |
| README.md | 7 роки тому | |
| main.js | 7 роки тому | |
| package-lock.json | 7 роки тому | |
| package.json | 7 роки тому |
stream-chain is a simple helper to create a chain of object-mode transform streams out of regular functions, asynchronous functions, generator functions, and existing Transform and Duplex object-mode streams.
It is distributed under New BSD license.
const Chain = require('stream-chain');
const chain = new Chain([
x => [x - 1, x, x + 1],
x => x * x,
async x => getFromDatabaseByKey(x),
function* (x) {
for (let i = x; i > 0; --i) {
yield i;
}
return 0;
}
]);
chain.on('data', data => console.log(data));
dataSource.pipe(chain.input);
npm i stream-chain
The main module provides a class based on EventEmitter. It chains its arguments in a single pipeline optionally binding common stream events.
The constructor accepts two parameters:
fns is an array of functions or instances of Duplex or Transform streams.
Transform stream is created, which calls this function with two parameters: chunk (an object), and an optional encoding. See documentation for more details on those parameters. The function will be called in the content of created stream.undefined or null. Two latter values indicate that no value should be passed.skipEvents is an optional Boolean parameter. If it is false (the default), 'error' events from all streams are forwarded to the created instance, 'data' and 'end' events are forwarded from the last stream of a pipeline. If it is true, no event forwarding is made.