ternary-stream
Advanced tools
Comparing version
25
index.js
'use strict'; | ||
var duplexer = require('duplexer'); | ||
var through2 = require('through2'); | ||
var ForkStream = require('fork-stream'); | ||
var eventStream = require('event-stream'); | ||
var duplexer2 = require('duplexer2'); | ||
@@ -25,18 +26,24 @@ module.exports = function (condition, trueStream, falseStream) { | ||
forkStream.a.pipe(trueStream); | ||
// then send down-stream | ||
trueStream.pipe(outStream); | ||
var mergedStream; | ||
if (falseStream) { | ||
// if there's an 'else' condition | ||
// if condition is false, pipe input to falseStream | ||
// if condition is false | ||
// pipe input to falseStream | ||
forkStream.b.pipe(falseStream); | ||
// then send down-stream | ||
falseStream.pipe(outStream); | ||
// merge output with trueStream's output | ||
mergedStream = eventStream.merge(falseStream, trueStream); | ||
} else { | ||
// if there's no 'else' condition | ||
// if condition is false, pipe down-stream | ||
forkStream.b.pipe(outStream); | ||
// if condition is false | ||
// merge output with trueStream's output | ||
mergedStream = eventStream.merge(forkStream.b, trueStream); | ||
} | ||
return duplexer(forkStream, outStream); | ||
// send everything down-stream | ||
mergedStream.pipe(outStream); | ||
// consumers write in to forkStream, we write out to outStream | ||
return duplexer2(forkStream, outStream); | ||
}; |
{ | ||
"name": "ternary-stream", | ||
"description": "Fork stream based on passed condition, and collect down-stream", | ||
"version": "1.0.1", | ||
"version": "1.1.0", | ||
"homepage": "https://github.com/robrich/ternary-stream", | ||
@@ -16,3 +16,4 @@ "repository": "git://github.com/robrich/ternary-stream.git", | ||
"dependencies": { | ||
"duplexer": "^0.1.1", | ||
"duplexer2": "^0.0.2", | ||
"event-stream": "^3.1.2", | ||
"fork-stream": "^0.0.4", | ||
@@ -19,0 +20,0 @@ "through2": "^0.4.1" |
27997
1.01%39
14.71%4
33.33%+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
+ Added
- Removed