react / react-0.13.3 / examples / basic-commonjs / node_modules / browserify / node_modules / labeled-stream-splicer / index.js
80709 viewsvar Splicer = require('stream-splicer');1var inherits = require('inherits');2var isarray = require('isarray');34module.exports = Labeled;5inherits(Labeled, Splicer);67module.exports.obj = function (streams, opts) {8if (!opts) opts = {};9opts.objectMode = true;10return new Labeled(streams, opts);11};1213function Labeled (streams, opts) {14if (!(this instanceof Labeled)) return new Labeled(streams, opts);15Splicer.call(this, [], opts);1617var reps = [];18for (var i = 0; i < streams.length; i++) {19var s = streams[i];20if (typeof s === 'string') continue;21if (isarray(s)) {22s = new Labeled(s, opts);23}24if (i >= 0 && typeof streams[i-1] === 'string') {25s.label = streams[i-1];26}27reps.push(s);28}29if (typeof streams[i-1] === 'string') {30reps.push(new Labeled([], opts));31}32this.splice.apply(this, [0,0].concat(reps));33}3435Labeled.prototype.indexOf = function (stream) {36if (typeof stream === 'string') {37for (var i = 0; i < this._streams.length; i++) {38if (this._streams[i].label === stream) return i;39}40return -1;41}42else {43return Splicer.prototype.indexOf.call(this, stream);44}45};4647Labeled.prototype.get = function (key) {48if (typeof key === 'string') {49var ix = this.indexOf(key);50if (ix < 0) return undefined;51return this._streams[ix];52}53else return Splicer.prototype.get.call(this, key);54};5556Labeled.prototype.splice = function (key) {57var ix;58if (typeof key === 'string') {59ix = this.indexOf(key);60}61else ix = key;62var args = [ ix ].concat([].slice.call(arguments, 1));63return Splicer.prototype.splice.apply(this, args);64};656667