Fork stream based on passed condition, and collect down-stream
npm install ternary-streamternary-stream !status
=======
A ternary stream: conditionally control the flow of stream data
js
var ternaryStream = require('ternary-stream');
var condition = function (data) {
return true;
};
process.stdin
.pipe(ternaryStream(condition, process.stdout))
.pipe(fs.createWriteStream('./out.txt'));
`
Data will conditionally go to stdout, and always go to the file
2: Ternary stream
Ternary
![][ternary]
`javascript
var ternaryStream = require('ternary-stream');
var through2 = require('through2');
var count = 0;
var condition = function (data) {
count++;
return count % 2;
};
process.stdin
.pipe(ternaryStream(condition, fs.createWriteStream('./truthy.txt'), fs.createWriteStream('./falsey.txt')))
.pipe(process.stdout);
`
Data will either go to truthy.txt (if condition is true) or falsey.txt (if condition is false) and will always go to stdout
API
$3
ternary-stream will pipe data to stream whenever condition is truthy.
If condition is falsey and elseStream is passed, data will pipe to elseStream.
After data is piped to stream or elseStream or neither, data is piped down-stream.
#### Parameters
##### condition
Type: function: takes in stream data and returns boolean
`js
function (data) {
return true; // or false
}
``