1.1.1 • Published 6 years ago

@nuintun/switch-stream v1.1.1

Weekly downloads
1
License
MIT
Repository
github
Last release
6 years ago

switch-stream

A stream condition for switch/case

NPM Version Download Status Dependencies

Usage

switch.png

const switchStream = require('switch-stream');

process.in
  .pipe(
    switchStream(
      buf => {
        if (buf > 0) {
          return 'case1';
        } else if (buf < 0) {
          return 'case2';
        }
      },
      {
        case1: streamA,
        case2: streamB
      }
    )
  )
  .pipe(process.stdout);

If buf great than 0, then pipe to streamA. If buf less than 0, then pipe to streamB. Otherwise buf equal to 0, pipe to output directly.

API

switchStream(switch, cases, options)

  • switch

    Switch condition determine which case will be choose. Switch can be any type, if switch is function, it will be called.

  • cases

    Choose which stream will be piped to by key switch return.

  • options The stream options settings.

Reference

Modify from popomore's stream-switch, but use stream3.

1.1.1

6 years ago

1.1.0

7 years ago

1.0.3

7 years ago

1.0.2

7 years ago

1.0.1

7 years ago

1.0.0

7 years ago

0.3.0

7 years ago

0.2.0

7 years ago

0.1.0

7 years ago

0.0.1

7 years ago