/conditional-stream

A duplex stream that only passes data through when a set function returns true

Primary LanguageJavaScript

conditional-stream

conditional-stream is a duplex stream that only passes data when a set function returns true

build status

requirements

install

  • npm install conditional-stream

example

to filter/limit a stream to only numbers

onlyNumbers.js

var CondStream = require('./index')
  , cond

cond = new CondStream(function(input) {
  // return true if input string is of type Number
  return (!isNaN(Number(input.toString())))
})

process.stdin.pipe(cond).pipe(process.stdout)

console

> echo 2 | node onlyNumbers.js
2

> echo a | node onlyNumbers.js
>

license

MIT