npm stats
  • Search
  • About
  • Repo
  • Sponsor
  • more
    • Search
    • About
    • Repo
    • Sponsor

Made by Antonio Ramirez

if-stream

2.0.0

@kevva

npmHomeRepoSnykSocket
Downloads:173
$ npm install if-stream
DailyWeeklyMonthlyYearly

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