🚨 Shai-Hulud Strikes Again:834 Packages Compromised.Technical Analysis →
Socket
Book a DemoInstallSign in
Socket

branch-pipe

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

branch-pipe

Simple syntax for branching and merging a stream

latest
Source
npmnpm
Version
1.0.1
Version published
Maintainers
1
Created
Source

branch-pipe v1.0.1

CircleCI codecov Standard - JavaScript Style Guide Greenkeeper badge

Simple syntax for branching and merging a stream

:cd: 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 = require('branch-pipe')
const gulp = require('gulp')

gulp.src('src/**/*.md')
  .pipe(branch(src => [
    src.pipe(foo()),
    src.pipe(bar()),
    src.pipe(baz())
  ]))
  .pipe(gulp.dest('dist'));

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.src('src/**/*.md')
  .pipe(foo())
  .pipe(gulp.dest('dist'));

gulp.src('src/**/*.md')
  .pipe(bar())
  .pipe(gulp.dest('dist'));

gulp.src('src/**/*.md')
  .pipe(baz())
  .pipe(gulp.dest('dist'));

That's it.

API

const branch = require('branch-pipe');

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 = branch(src => [src.pipe(foo()), src.pipe(bar())])

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

Keywords

fork

FAQs

Package last updated on 26 Jan 2017

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts