UNPKG

motion

Version:

motion - moving development forward

73 lines (72 loc) 5.42 kB
{ "_args": [ [ "ternary-stream@https://registry.npmjs.org/ternary-stream/-/ternary-stream-2.0.0.tgz", "/Users/nw/flint/packages/flint" ] ], "_from": "ternary-stream@>=2.0.0 <3.0.0", "_id": "ternary-stream@2.0.0", "_inCache": true, "_location": "/ternary-stream", "_phantomChildren": {}, "_requested": { "name": "ternary-stream", "raw": "ternary-stream@https://registry.npmjs.org/ternary-stream/-/ternary-stream-2.0.0.tgz", "rawSpec": "https://registry.npmjs.org/ternary-stream/-/ternary-stream-2.0.0.tgz", "scope": null, "spec": "https://registry.npmjs.org/ternary-stream/-/ternary-stream-2.0.0.tgz", "type": "remote" }, "_requiredBy": [ "/gulp-if" ], "_resolved": "https://registry.npmjs.org/ternary-stream/-/ternary-stream-2.0.0.tgz", "_shasum": "569fa9042b01456b7a1277c64f41d643d84570e6", "_shrinkwrap": null, "_spec": "ternary-stream@https://registry.npmjs.org/ternary-stream/-/ternary-stream-2.0.0.tgz", "_where": "/Users/nw/flint/packages/flint", "author": { "name": "Rob Richardson", "url": "http://robrich.org/" }, "bugs": { "url": "https://github.com/robrich/ternary-stream/issues" }, "dependencies": { "duplexify": "^3.4.2", "fork-stream": "^0.0.4", "merge-stream": "^1.0.0", "through2": "^2.0.0" }, "description": "Fork stream based on passed condition, and collect down-stream", "devDependencies": { "jshint": "^2.8.0", "mocha": "^2.3.3", "should": "^7.1.0" }, "engines": { "node": ">= 0.10.0" }, "homepage": "https://github.com/robrich/ternary-stream", "keywords": [ "conditional", "if", "stream", "ternary" ], "license": "MIT", "main": "./index.js", "name": "ternary-stream", "optionalDependencies": {}, "readme": "ternary-stream ![status](https://secure.travis-ci.org/robrich/ternary-stream.png?branch=master)\r\n=======\r\n\r\nA ternary stream: conditionally control the flow of stream data\r\n\r\n## Usage\r\n\r\n1: Conditionally filter content\r\n\r\n**Condition**\r\n\r\n![][condition]\r\n\r\nif the condition returns truthy, data is piped to the child stream\r\n\r\n```js\r\nvar ternaryStream = require('ternary-stream');\r\n\r\nvar condition = function (data) {\r\n return true;\r\n};\r\n\r\nprocess.stdin\r\n .pipe(ternaryStream(condition, process.stdout))\r\n .pipe(fs.createWriteStream('./out.txt'));\r\n});\r\n```\r\n\r\nData will conditionally go to stdout, and always go to the file\r\n\r\n2: Ternary stream\r\n\r\n**Ternary**\r\n\r\n![][ternary]\r\n\r\n\r\n```javascript\r\nvar ternaryStream = require('ternary-stream');\r\nvar through2 = require('through2');\r\n\r\nvar count = 0;\r\nvar condition = function (data) {\r\n count++;\r\n return count % 2;\r\n};\r\n\r\nprocess.stdin\r\n .pipe(ternaryStream(condition, fs.createWriteStream('./truthy.txt'), fs.createWriteStream('./falsey.txt')))\r\n .pipe(process.stdout);\r\n});\r\n```\r\n\r\nData will either go to truthy.txt (if condition is true) or falsey.txt (if condition is false) and will always go to stdout\r\n\r\n## API\r\n\r\n### ternaryStream(condition, stream [, elseStream])\r\n\r\nternary-stream will pipe data to `stream` whenever `condition` is truthy.\r\n\r\nIf `condition` is falsey and `elseStream` is passed, data will pipe to `elseStream`.\r\n\r\nAfter data is piped to `stream` or `elseStream` or neither, data is piped down-stream.\r\n\r\n#### Parameters\r\n\r\n##### condition\r\n\r\nType: `function`: takes in stream data and returns `boolean`\r\n\r\n```js\r\nfunction (data) {\r\n\treturn true; // or false\r\n}\r\n```\r\n\r\n##### stream\r\n\r\nStream for ternary-stream to pipe data into when condition is truthy.\r\n\r\n##### elseStream\r\n\r\nOptional, Stream for ternary-stream to pipe data into when condition is falsey.\r\n\r\n\r\nLICENSE\r\n-------\r\n\r\n(MIT License)\r\n\r\nCopyright (c) 2014 [Richardson & Sons, LLC](http://richardsonandsons.com/)\r\n\r\nPermission is hereby granted, free of charge, to any person obtaining\r\na copy of this software and associated documentation files (the\r\n\"Software\"), to deal in the Software without restriction, including\r\nwithout limitation the rights to use, copy, modify, merge, publish,\r\ndistribute, sublicense, and/or sell copies of the Software, and to\r\npermit persons to whom the Software is furnished to do so, subject to\r\nthe following conditions:\r\n\r\nThe above copyright notice and this permission notice shall be\r\nincluded in all copies or substantial portions of the Software.\r\n\r\nTHE SOFTWARE IS PROVIDED \"AS IS\", WITHOUT WARRANTY OF ANY KIND,\r\nEXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF\r\nMERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND\r\nNONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE\r\nLIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION\r\nOF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION\r\nWITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.\r\n\r\n[condition]: https://rawgithub.com/robrich/ternary-stream/master/img/condition.svg\r\n[ternary]: https://rawgithub.com/robrich/ternary-stream/master/img/ternary.svg\r\n", "readmeFilename": "README.md", "repository": { "type": "git", "url": "git://github.com/robrich/ternary-stream.git" }, "scripts": { "test": "mocha && jshint ." }, "version": "2.0.0" }