branch-pipe v1.0.1
Simple syntax for branching and merging a stream
💿 Install
npm i branch-pipe
Feature
With this module, you can branch the input stream into any number of branches and transform them in different way branch by branch, and then merge the all the results.
Example
For example, when you're working with gulp:
const branch = const gulp = gulp ;
The above splits the input stream gulp.src('src/**/*.md')
into 3 different branches, and transform it with 3 different ways foo()
, bar()
and baz()
.
The above is equivalent of the below:
gulp ; gulp ; gulp ;
That's it.
API
const branch = ;
branch([options,] func)
- @param {Object} options - The options
- @param {boolean} options.objectMode - Set this true when you're working with object stream. default is false.
- @param {number} options.highWaterMark - The high water mark of this stream.
- @param {Function} func - The branch description function
- @return {Transform}
This takes one argument func
and it should return an array of readable streams. The returned streams are joined into a single stream and its output becomes the output of the returned transform stream of the entire call.
For example:
const transform =
transform
is a transform stream. Inputs are piped into both foo()
and bar()
and the outputs are the merged stream of the outputs of both foo()
and bar()
.
branch.obj([options,] func)
The shorthand for the object mode of the above. The behavior is the same as the above exceptthat default of options.objectMode is true
and default of options.highWaterMark is 16
.
License
MIT