Socket
Book a DemoInstallSign in
Socket

if-stream

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

if-stream

Conditionally return a stream

latest
Source
npmnpm
Version
2.0.0
Version published
Maintainers
1
Created
Source

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

Keywords

conditional

FAQs

Package last updated on 06 May 2016

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