pax_global_header00006660000000000000000000000064126206676320014524gustar00rootroot0000000000000052 comment=496456754b3cf8faabd320181374ef0bdb664820 get-stdin-5.0.1/000077500000000000000000000000001262066763200134255ustar00rootroot00000000000000get-stdin-5.0.1/.editorconfig000066400000000000000000000003471262066763200161060ustar00rootroot00000000000000root = true [*] indent_style = tab end_of_line = lf charset = utf-8 trim_trailing_whitespace = true insert_final_newline = true [{package.json,*.yml}] indent_style = space indent_size = 2 [*.md] trim_trailing_whitespace = false get-stdin-5.0.1/.gitattributes000066400000000000000000000000141262066763200163130ustar00rootroot00000000000000* text=auto get-stdin-5.0.1/.gitignore000066400000000000000000000000151262066763200154110ustar00rootroot00000000000000node_modules get-stdin-5.0.1/.travis.yml000066400000000000000000000000771262066763200155420ustar00rootroot00000000000000sudo: false language: node_js node_js: - 'stable' - '0.12' get-stdin-5.0.1/index.js000066400000000000000000000014371262066763200150770ustar00rootroot00000000000000'use strict'; var stdin = process.stdin; module.exports = function () { var ret = ''; return new Promise(function (resolve) { if (stdin.isTTY) { resolve(ret); return; } stdin.setEncoding('utf8'); stdin.on('readable', function () { var chunk; while ((chunk = stdin.read())) { ret += chunk; } }); stdin.on('end', function () { resolve(ret); }); }); }; module.exports.buffer = function () { var ret = []; var len = 0; return new Promise(function (resolve) { if (stdin.isTTY) { resolve(new Buffer('')); return; } stdin.on('readable', function () { var chunk; while ((chunk = stdin.read())) { ret.push(chunk); len += chunk.length; } }); stdin.on('end', function () { resolve(Buffer.concat(ret, len)); }); }); }; get-stdin-5.0.1/license000066400000000000000000000021371262066763200147750ustar00rootroot00000000000000The MIT License (MIT) 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-5.0.1/package.json000066400000000000000000000013101262066763200157060ustar00rootroot00000000000000{ "name": "get-stdin", "version": "5.0.1", "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": ">=0.12.0" }, "scripts": { "test": "xo && ava test.js && echo unicorns | ava test-real.js" }, "files": [ "index.js" ], "keywords": [ "std", "stdin", "stdio", "concat", "buffer", "stream", "process", "read" ], "devDependencies": { "ava": "*", "buffer-equals": "^1.0.3", "xo": "*" }, "xo": { "ignores": [ "test.js" ] } } get-stdin-5.0.1/readme.md000066400000000000000000000020351262066763200152040ustar00rootroot00000000000000# 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 --save 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](http://sindresorhus.com) get-stdin-5.0.1/test-real.js000066400000000000000000000001051262066763200156570ustar00rootroot00000000000000import fn from './'; fn().then(data => process.exit(data ? 0 : 1)); get-stdin-5.0.1/test.js000066400000000000000000000015501262066763200147430ustar00rootroot00000000000000import test from 'ava'; import bufferEquals from 'buffer-equals'; import fn from './'; test.serial('get stdin', async t => { process.stdin.isTTY = false; setImmediate(() => { process.stdin.push('unicorns'); process.stdin.emit('end'); }); t.is((await fn()).trim(), 'unicorns'); }); test.serial('get empty string when no stdin', async t => { process.stdin.isTTY = true; t.is(await fn(), ''); }); test.serial('get stdin as a buffer', t => { process.stdin.isTTY = false; const promise = fn.buffer(data => { t.true(bufferEquals(data, new Buffer('unicorns'))); t.is(data.toString().trim(), 'unicorns'); }); process.stdin.push(new Buffer('unicorns')); process.stdin.emit('end'); return promise; }); test.serial('get empty buffer when no stdin', async t => { process.stdin.isTTY = true; t.true(bufferEquals(await fn.buffer(), new Buffer(''))); });