2.0.0 • Published 8 years ago

if-stream v2.0.0

Weekly downloads
2
License
MIT
Repository
github
Last release
8 years ago

if-stream Build Status

Conditionally return a stream

Install

$ npm install --save if-stream

Usage

const csvParser = require('csv-parser');
const ifStream = require('if-stream');

const isCsv = data => data.toString().indexOf(',') !== -1;
const stream = ifStream(isCsv, csvParser);

stream.on('data', data => {
	console.log(data);
	//=> {foo: 'bar', unicorn: 'cat'}
});

stream.end('foo,unicorn\nbar,cat\n');

API

ifStream(condition, stream, optionalStream, options)

condition

Type: function, string, boolean, regex

Condition to match the stream buffer against.

stream

Type: stream

The stream to be returned if the condition is met.

optionalStream

Type: stream

An optional stream to be returned if the condition isn't met. By default a transform stream is returned.

options

Type: object

Options to pass to peek-stream.

License

MIT © Kevin Martensson