pax_global_header00006660000000000000000000000064134717443230014522gustar00rootroot0000000000000052 comment=31dbd99c6dabb11e1bd7f4fa8194c5dd0d877296 labeled-stream-splicer-2.0.2/000077500000000000000000000000001347174432300160435ustar00rootroot00000000000000labeled-stream-splicer-2.0.2/.npmrc000066400000000000000000000000231347174432300171560ustar00rootroot00000000000000package-lock=false labeled-stream-splicer-2.0.2/.travis.yml000066400000000000000000000005611347174432300201560ustar00rootroot00000000000000language: node_js node_js: - "12" - "11" - "10" - "8" - "6" - "4" - "iojs" - "0.12" - "0.10" - "0.8" before_install: # Old npm certs are untrusted https://github.com/npm/npm/issues/20191 - 'if [ "${TRAVIS_NODE_VERSION}" = "0.6" ] || [ "${TRAVIS_NODE_VERSION}" = "0.8" ]; then export NPM_CONFIG_STRICT_SSL=false; fi' - 'nvm install-latest-npm' labeled-stream-splicer-2.0.2/LICENSE000066400000000000000000000021201347174432300170430ustar00rootroot00000000000000The MIT License (MIT) Copyright (c) James Halliday and browserify contributors Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. labeled-stream-splicer-2.0.2/example/000077500000000000000000000000001347174432300174765ustar00rootroot00000000000000labeled-stream-splicer-2.0.2/example/browser/000077500000000000000000000000001347174432300211615ustar00rootroot00000000000000labeled-stream-splicer-2.0.2/example/browser/bar.js000066400000000000000000000000671347174432300222660ustar00rootroot00000000000000module.exports = function (n) { return n * 100; }; labeled-stream-splicer-2.0.2/example/browser/foo.js000066400000000000000000000001351347174432300223010ustar00rootroot00000000000000var bar = require('./bar'); module.exports = function (n) { return n * 111 + bar(n); }; labeled-stream-splicer-2.0.2/example/browser/main.js000066400000000000000000000000741347174432300224440ustar00rootroot00000000000000var foo = require('./foo'); console.log('main: ' + foo(5)); labeled-stream-splicer-2.0.2/example/browser/xyz.js000066400000000000000000000000731347174432300223510ustar00rootroot00000000000000var foo = require('./foo'); console.log('xyz: ' + foo(6)); labeled-stream-splicer-2.0.2/example/bundle.js000066400000000000000000000007101347174432300213030ustar00rootroot00000000000000var splicer = require('../'); var through = require('through2'); var deps = require('module-deps'); var pack = require('browser-pack'); var pipeline = splicer.obj([ 'deps', [ deps() ], 'pack', [ pack({ raw: true }) ] ]); pipeline.get('deps').push(through.obj(function (row, enc, next) { row.source = row.source.toUpperCase(); this.push(row); next(); })); pipeline.pipe(process.stdout); pipeline.end(__dirname + '/browser/main.js'); labeled-stream-splicer-2.0.2/index.js000066400000000000000000000033311347174432300175100ustar00rootroot00000000000000var Splicer = require('stream-splicer'); var inherits = require('inherits'); module.exports = Labeled; inherits(Labeled, Splicer); module.exports.obj = function (streams, opts) { if (!opts) opts = {}; opts.objectMode = true; return new Labeled(streams, opts); }; function Labeled (streams, opts) { if (!(this instanceof Labeled)) return new Labeled(streams, opts); Splicer.call(this, [], opts); var reps = []; for (var i = 0; i < streams.length; i++) { var s = streams[i]; if (typeof s === 'string') continue; if (Array.isArray(s)) { s = new Labeled(s, opts); } if (i >= 0 && typeof streams[i-1] === 'string') { s.label = streams[i-1]; } reps.push(s); } if (typeof streams[i-1] === 'string') { reps.push(new Labeled([], opts)); } this.splice.apply(this, [0,0].concat(reps)); } Labeled.prototype.indexOf = function (stream) { if (typeof stream === 'string') { for (var i = 0; i < this._streams.length; i++) { if (this._streams[i].label === stream) return i; } return -1; } else { return Splicer.prototype.indexOf.call(this, stream); } }; Labeled.prototype.get = function (key) { if (typeof key === 'string') { var ix = this.indexOf(key); if (ix < 0) return undefined; return this._streams[ix]; } else return Splicer.prototype.get.call(this, key); }; Labeled.prototype.splice = function (key) { var ix; if (typeof key === 'string') { ix = this.indexOf(key); } else ix = key; var args = [ ix ].concat([].slice.call(arguments, 1)); return Splicer.prototype.splice.apply(this, args); }; labeled-stream-splicer-2.0.2/package.json000066400000000000000000000015041347174432300203310ustar00rootroot00000000000000{ "name": "labeled-stream-splicer", "version": "2.0.2", "description": "stream splicer with labels", "main": "index.js", "dependencies": { "inherits": "^2.0.1", "stream-splicer": "^2.0.0" }, "devDependencies": { "browser-pack": "^6.1.0", "concat-stream": "^1.4.6", "module-deps": "^6.2.0", "tape": "^4.10.1", "through2": "^1.0.0" }, "scripts": { "test": "tape test/*.js" }, "repository": { "type": "git", "url": "git://github.com/browserify/labeled-stream-splicer.git" }, "homepage": "https://github.com/browserify/labeled-stream-splicer", "keywords": [ "splice", "stream", "labels", "mutable", "pipeline" ], "author": { "name": "James Halliday", "email": "mail@substack.net", "url": "http://substack.net" }, "license": "MIT" } labeled-stream-splicer-2.0.2/readme.markdown000066400000000000000000000064221347174432300210500ustar00rootroot00000000000000# labeled-stream-splicer [stream splicer](https://npmjs.org/package/stream-splicer) with labels [![build status](https://secure.travis-ci.org/browserify/labeled-stream-splicer.png?branch=master)](http://travis-ci.org/browserify/labeled-stream-splicer) # example Here's an example that exposes a label for `deps` and `pack`: ``` js var splicer = require('labeled-stream-splicer'); var through = require('through2'); var deps = require('module-deps'); var pack = require('browser-pack'); var lstream = require('lstream'); var pipeline = splicer.obj([ 'deps', [ deps() ], 'pack', [ pack({ raw: true }) ] ]); pipeline.get('deps').unshift(lstream()); pipeline.get('deps').push(through.obj(function (row, enc, next) { row.source = row.source.toUpperCase(); this.push(row); next(); })); process.stdin.pipe(pipeline).pipe(process.stdout); ``` Here the `deps` sub-pipeline is augmented with a post-transformation that uppercases its source input. # methods ``` js var splicer = require('labeled-stream-splicer') ``` The API is the same as [stream-splicer](https://npmjs.org/package/stream-splicer), except that `pipeline.get()`, `pipeline.splice()`, and `pipeline.indexOf()` can accept string labels in addition to numeric indexes. ## var pipeline = splicer(streams, opts) Create a `pipeline` duplex stream given an array of `streams`. Each `stream` will be piped to the next. Writes to `pipeline` get written to the first stream and data for reads from `pipeline` come from the last stream. To signify a label, a stream may have a `.label` property or a string may be placed in the `streams` array. For example, for streams `[ a, 'foo', b, c, 'bar', d ]`, this pipeline is constructed internally: ``` a.pipe(b).pipe(c).pipe(d) ``` with a label `'foo`' that points to `b` and a label `'bar'` that points to `d`. If `a` or `c` has a `.label` property, that label would be used for addressing. Input will get written into `a`. Output will be read from `d`. If any of the elements in `streams` are arrays, they will be converted into nested labeled pipelines. This is useful if you want to expose a hookable pipeline with grouped insertion points. ## var pipeline = splicer.obj(streams, opts) Create a `pipeline` with `opts.objectMode` set to true for convenience. ## var removed = pipeline.splice(index, howMany, stream, ...) Splice the pipeline starting at `index`, removing `howMany` streams and replacing them with each additional `stream` argument provided. The streams that were removed from the splice and returned. `index` can be an integer index or a label. ## pipeline.push(stream, ...) Push one or more streams to the end of the pipeline. The stream arguments may have a `label` property that will be used for string lookups. ## var stream = pipeline.pop() Pop a stream from the end of the pipeline. ## pipeline.unshift(stream, ...) Unshift one or more streams to the begining of the pipeline. The stream arguments may have a `label` property that will be used for string lookups. ## var stream = pipeline.shift() Shift a stream from the begining of the pipeline. ## var stream = pipeline.get(index) Return the stream at index `index`. `index` can be an integer or a string label. # install With [npm](https://npmjs.org) do: ``` npm install labeled-stream-splicer ``` # license MIT labeled-stream-splicer-2.0.2/test/000077500000000000000000000000001347174432300170225ustar00rootroot00000000000000labeled-stream-splicer-2.0.2/test/bundle.js000066400000000000000000000014351347174432300206340ustar00rootroot00000000000000var test = require('tape'); var splicer = require('../'); var through = require('through2'); var deps = require('module-deps'); var pack = require('browser-pack'); var concat = require('concat-stream'); test('bundle', function (t) { t.plan(1); var pipeline = splicer.obj([ 'deps', [ deps() ], 'pack', [ pack({ raw: true }) ] ]); pipeline.pipe(concat(function (body) { Function([ 'console' ], body.toString('utf8'))({ log: log }); function log (msg) { t.equal(msg, 'main: 56055'); } })); pipeline.get('deps').push(through.obj(function (row, enc, next) { row.source = row.source.replace(/111/g, '11111'); this.push(row); next(); })); pipeline.end(__dirname + '/bundle/main.js'); }); labeled-stream-splicer-2.0.2/test/bundle/000077500000000000000000000000001347174432300202735ustar00rootroot00000000000000labeled-stream-splicer-2.0.2/test/bundle/bar.js000066400000000000000000000000671347174432300214000ustar00rootroot00000000000000module.exports = function (n) { return n * 100; }; labeled-stream-splicer-2.0.2/test/bundle/foo.js000066400000000000000000000001351347174432300214130ustar00rootroot00000000000000var bar = require('./bar'); module.exports = function (n) { return n * 111 + bar(n); }; labeled-stream-splicer-2.0.2/test/bundle/main.js000066400000000000000000000000741347174432300215560ustar00rootroot00000000000000var foo = require('./foo'); console.log('main: ' + foo(5)); labeled-stream-splicer-2.0.2/test/bundle/xyz.js000066400000000000000000000000731347174432300214630ustar00rootroot00000000000000var foo = require('./foo'); console.log('xyz: ' + foo(6));