diff options
Diffstat (limited to 'node_modules/get-stdin')
-rw-r--r-- | node_modules/get-stdin/index.js | 52 | ||||
-rw-r--r-- | node_modules/get-stdin/license | 9 | ||||
-rw-r--r-- | node_modules/get-stdin/package.json | 71 | ||||
-rw-r--r-- | node_modules/get-stdin/readme.md | 55 |
4 files changed, 187 insertions, 0 deletions
diff --git a/node_modules/get-stdin/index.js b/node_modules/get-stdin/index.js new file mode 100644 index 0000000..b7483e4 --- /dev/null +++ b/node_modules/get-stdin/index.js @@ -0,0 +1,52 @@ +'use strict'; +const stdin = process.stdin; + +module.exports = () => { + let ret = ''; + + return new Promise(resolve => { + if (stdin.isTTY) { + resolve(ret); + return; + } + + stdin.setEncoding('utf8'); + + stdin.on('readable', () => { + let chunk; + + while ((chunk = stdin.read())) { + ret += chunk; + } + }); + + stdin.on('end', () => { + resolve(ret); + }); + }); +}; + +module.exports.buffer = () => { + const ret = []; + let len = 0; + + return new Promise(resolve => { + if (stdin.isTTY) { + resolve(Buffer.concat([])); + return; + } + + stdin.on('readable', () => { + let chunk; + + while ((chunk = stdin.read())) { + ret.push(chunk); + len += chunk.length; + } + }); + + stdin.on('end', () => { + resolve(Buffer.concat(ret, len)); + }); + }); +}; diff --git a/node_modules/get-stdin/license b/node_modules/get-stdin/license new file mode 100644 index 0000000..e7af2f7 --- /dev/null +++ b/node_modules/get-stdin/license @@ -0,0 +1,9 @@ +MIT License + +Copyright (c) Sindre Sorhus <[email protected]> (sindresorhus.com) + +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. diff --git a/node_modules/get-stdin/package.json b/node_modules/get-stdin/package.json new file mode 100644 index 0000000..1b73940 --- /dev/null +++ b/node_modules/get-stdin/package.json @@ -0,0 +1,71 @@ +{ + "_args": [ + [ + "[email protected]", + "/home/dstaesse/git/website" + ] + ], + "_development": true, + "_from": "[email protected]", + "_id": "[email protected]", + "_inBundle": false, + "_integrity": "sha512-jp4tHawyV7+fkkSKyvjuLZswblUtz+SQKzSWnBbii16BuZksJlU1wuBYXY75r+duh/llF1ur6oNwi+2ZzjKZ7g==", + "_location": "/get-stdin", + "_phantomChildren": {}, + "_requested": { + "type": "version", + "registry": true, + "raw": "[email protected]", + "name": "get-stdin", + "escapedName": "get-stdin", + "rawSpec": "6.0.0", + "saveSpec": null, + "fetchSpec": "6.0.0" + }, + "_requiredBy": [ + "/postcss-cli" + ], + "_resolved": "https://registry.npmjs.org/get-stdin/-/get-stdin-6.0.0.tgz", + "_spec": "6.0.0", + "_where": "/home/dstaesse/git/website", + "author": { + "name": "Sindre Sorhus", + "email": "[email protected]", + "url": "sindresorhus.com" + }, + "bugs": { + "url": "https://github.com/sindresorhus/get-stdin/issues" + }, + "description": "Get stdin as a string or buffer", + "devDependencies": { + "ava": "*", + "xo": "*" + }, + "engines": { + "node": ">=4" + }, + "files": [ + "index.js" + ], + "homepage": "https://github.com/sindresorhus/get-stdin#readme", + "keywords": [ + "std", + "stdin", + "stdio", + "concat", + "buffer", + "stream", + "process", + "read" + ], + "license": "MIT", + "name": "get-stdin", + "repository": { + "type": "git", + "url": "git+https://github.com/sindresorhus/get-stdin.git" + }, + "scripts": { + "test": "xo && ava test.js test-buffer.js && echo unicorns | node test-real.js" + }, + "version": "6.0.0" +} diff --git a/node_modules/get-stdin/readme.md b/node_modules/get-stdin/readme.md new file mode 100644 index 0000000..cc9ec1a --- /dev/null +++ b/node_modules/get-stdin/readme.md @@ -0,0 +1,55 @@ +# get-stdin [![Build Status](https://travis-ci.org/sindresorhus/get-stdin.svg?branch=master)](https://travis-ci.org/sindresorhus/get-stdin) + +> Get [stdin](https://nodejs.org/api/process.html#process_process_stdin) as a string or buffer + + +## Install + +``` +$ npm install get-stdin +``` + + +## Usage + +```js +// example.js +const getStdin = require('get-stdin'); + +getStdin().then(str => { + console.log(str); + //=> 'unicorns' +}); +``` + +``` +$ echo unicorns | node example.js +unicorns +``` + + +## API + +Both methods returns a promise that is resolved when the `end` event fires on the `stdin` stream, indicating that there is no more data to be read. + +### getStdin() + +Get `stdin` as a `string`. + +In a TTY context, a promise that resolves to an empty string is returned. + +### getStdin.buffer() + +Get `stdin` as a `Buffer`. + +In a TTY context, a promise that resolves to an empty buffer is returned. + + +## Related + +- [get-stream](https://github.com/sindresorhus/get-stream) - Get a stream as a string or buffer + + +## License + +MIT © [Sindre Sorhus](https://sindresorhus.com) |