pax_global_header00006660000000000000000000000064132463124740014520gustar00rootroot0000000000000052 comment=83c5c9f9059f0a66a6c9acef03c19546e2cb175b get-stdin-6.0.0/000077500000000000000000000000001324631247400134215ustar00rootroot00000000000000get-stdin-6.0.0/.editorconfig000066400000000000000000000002571324631247400161020ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [*.yml] indent_style = space indent_size = 2 get-stdin-6.0.0/.gitattributes000066400000000000000000000000351324631247400163120ustar00rootroot00000000000000* text=auto *.js text eol=lf get-stdin-6.0.0/.gitignore000066400000000000000000000000271324631247400154100ustar00rootroot00000000000000node_modules yarn.lock get-stdin-6.0.0/.npmrc000066400000000000000000000000231324631247400145340ustar00rootroot00000000000000package-lock=false get-stdin-6.0.0/.travis.yml000066400000000000000000000000771324631247400155360ustar00rootroot00000000000000sudo: false language: node_js node_js: - '8' - '6' - '4' get-stdin-6.0.0/index.js000066400000000000000000000013621324631247400150700ustar00rootroot00000000000000'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)); }); }); }; get-stdin-6.0.0/license000066400000000000000000000021251324631247400147660ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (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. get-stdin-6.0.0/package.json000066400000000000000000000011151324631247400157050ustar00rootroot00000000000000{ "name": "get-stdin", "version": "6.0.0", "description": "Get stdin as a string or buffer", "license": "MIT", "repository": "sindresorhus/get-stdin", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "sindresorhus.com" }, "engines": { "node": ">=4" }, "scripts": { "test": "xo && ava test.js test-buffer.js && echo unicorns | node test-real.js" }, "files": [ "index.js" ], "keywords": [ "std", "stdin", "stdio", "concat", "buffer", "stream", "process", "read" ], "devDependencies": { "ava": "*", "xo": "*" } } get-stdin-6.0.0/readme.md000066400000000000000000000020331324631247400151760ustar00rootroot00000000000000# 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) get-stdin-6.0.0/test-buffer.js000066400000000000000000000010201324631247400161760ustar00rootroot00000000000000import test from 'ava'; import m from '.'; test.serial('get stdin', async t => { t.plan(2); process.stdin.isTTY = false; const promise = m.buffer(); process.stdin.push(Buffer.from('uni')); process.stdin.push(Buffer.from('corns')); process.stdin.emit('end'); const data = await promise; t.true(data.equals(Buffer.from('unicorns'))); t.is(data.toString(), 'unicorns'); }); test.serial('get empty buffer when no stdin', async t => { process.stdin.isTTY = true; t.true((await m.buffer()).equals(Buffer.from(''))); }); get-stdin-6.0.0/test-real.js000066400000000000000000000002121324631247400156520ustar00rootroot00000000000000'use strict'; const m = require('.'); m().then(data => { process.exit(data ? 0 : 1); // eslint-disable-line unicorn/no-process-exit }); get-stdin-6.0.0/test.js000066400000000000000000000006121324631247400147350ustar00rootroot00000000000000import test from 'ava'; import m from '.'; test.serial('get stdin', async t => { t.plan(1); process.stdin.isTTY = false; const promise = m(); process.stdin.push('uni'); process.stdin.push('corns'); process.stdin.emit('end'); t.is((await promise).trim(), 'unicorns'); }); test.serial('get empty string when no stdin', async t => { process.stdin.isTTY = true; t.is(await m(), ''); });