splinter
Split an object-mode stream into multiple streams by filtering the chunks
Install
npm install --save splinter
Example Usage
var Splinter = ; // create a new instancevar splinter = { // this converts the chunk into a value that can be matched against return typeofchunk;}; // create some new output streamsvar booleans = splintervar numbers = splinter;var objects = splinter; // send some data into the splintersplinter;splinter;splinter; // ... and it is automatically sent to the right outputbooleans; // truenumbers; // 10objects; // { foo: 'bar' } // ... anything that doesn't match will be passed through the splintersplinter;splinter; // 'no matches'
API
Splinter([toValue])
Create a new instance. Can be called with or without new
.
Inherits from Stream.Transform
.
Parameters:
toValue
: optional. Converts the chunk into a value. By default it just uses the chunk as the value.
Example:
var splinter = { return chunklength;}; splinter; // match chunks with a length of 3
Splinter.prototype.match(value)
Parameters:
value
: What to check the chunk against. Can be a value or a function.
Returns:
A Readable stream that will output any chunks that match the value
.
Example:
var splinter = ; // match against a valuevar streamA = splinter; // match against an object with deep equalityvar streamB = splinter; // functions are passed the output of `toValue`.var streamC = splinter;
License
MIT