pax_global_header00006660000000000000000000000064136564603560014530gustar00rootroot0000000000000052 comment=07288e101242054df3c197abc5559458af6c78ba get-stdin-8.0.0/000077500000000000000000000000001365646035600134335ustar00rootroot00000000000000get-stdin-8.0.0/.editorconfig000066400000000000000000000002571365646035600161140ustar00rootroot00000000000000root = 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-8.0.0/.gitattributes000066400000000000000000000000231365646035600163210ustar00rootroot00000000000000* text=auto eol=lf get-stdin-8.0.0/.github/000077500000000000000000000000001365646035600147735ustar00rootroot00000000000000get-stdin-8.0.0/.github/funding.yml000066400000000000000000000001631365646035600171500ustar00rootroot00000000000000github: sindresorhus open_collective: sindresorhus tidelift: npm/get-stdin custom: https://sindresorhus.com/donate get-stdin-8.0.0/.github/security.md000066400000000000000000000002631365646035600171650ustar00rootroot00000000000000# Security Policy To report a security vulnerability, please use the [Tidelift security contact](https://tidelift.com/security). Tidelift will coordinate the fix and disclosure. get-stdin-8.0.0/.gitignore000066400000000000000000000000271365646035600154220ustar00rootroot00000000000000node_modules yarn.lock get-stdin-8.0.0/.npmrc000066400000000000000000000000231365646035600145460ustar00rootroot00000000000000package-lock=false get-stdin-8.0.0/.travis.yml000066400000000000000000000000661365646035600155460ustar00rootroot00000000000000language: node_js node_js: - '14' - '12' - '10' get-stdin-8.0.0/index.d.ts000066400000000000000000000016111365646035600153330ustar00rootroot00000000000000/// declare const getStdin: { /** Get [`stdin`](https://nodejs.org/api/process.html#process_process_stdin) as a `string`. @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. In a TTY context, an empty `string` is returned. @example ``` // example.ts import getStdin = require('get-stdin'); (async () => { console.log(await getStdin()); //=> 'unicorns' }) // $ echo unicorns | ts-node example.ts // unicorns ``` */ (): Promise; /** Get [`stdin`](https://nodejs.org/api/process.html#process_process_stdin) as a `Buffer`. @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. In a TTY context, an empty `Buffer` is returned. */ buffer(): Promise; }; export = getStdin; get-stdin-8.0.0/index.js000066400000000000000000000007611365646035600151040ustar00rootroot00000000000000'use strict'; const {stdin} = process; module.exports = async () => { let result = ''; if (stdin.isTTY) { return result; } stdin.setEncoding('utf8'); for await (const chunk of stdin) { result += chunk; } return result; }; module.exports.buffer = async () => { const result = []; let length = 0; if (stdin.isTTY) { return Buffer.concat([]); } for await (const chunk of stdin) { result.push(chunk); length += chunk.length; } return Buffer.concat(result, length); }; get-stdin-8.0.0/index.test-d.ts000066400000000000000000000002321365646035600163060ustar00rootroot00000000000000import {expectType} from 'tsd'; import getStdin = require('.'); expectType>(getStdin()); expectType>(getStdin.buffer()); get-stdin-8.0.0/license000066400000000000000000000021351365646035600150010ustar00rootroot00000000000000MIT License Copyright (c) Sindre Sorhus (https://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-8.0.0/package.json000066400000000000000000000013661365646035600157270ustar00rootroot00000000000000{ "name": "get-stdin", "version": "8.0.0", "description": "Get stdin as a string or buffer", "license": "MIT", "repository": "sindresorhus/get-stdin", "funding": "https://github.com/sponsors/sindresorhus", "author": { "name": "Sindre Sorhus", "email": "sindresorhus@gmail.com", "url": "https://sindresorhus.com" }, "engines": { "node": ">=10" }, "scripts": { "test": "xo && ava test.js test-buffer.js && echo unicorns | node test-real.js && tsd" }, "files": [ "index.js", "index.d.ts" ], "keywords": [ "std", "stdin", "stdio", "concat", "buffer", "stream", "process", "read" ], "devDependencies": { "@types/node": "^13.13.5", "ava": "^2.4.0", "delay": "^4.2.0", "tsd": "^0.11.0", "xo": "^0.24.0" } } get-stdin-8.0.0/readme.md000066400000000000000000000026251365646035600152170ustar00rootroot00000000000000# get-stdin [![Build Status](https://travis-ci.com/sindresorhus/get-stdin.svg?branch=master)](https://travis-ci.com/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'); (async () => { console.log(await getStdin()); //=> '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 ---
Get professional support for this package with a Tidelift subscription
Tidelift helps make open source sustainable for maintainers while giving companies
assurances about security, maintenance, and licensing for their dependencies.
get-stdin-8.0.0/test-buffer.js000066400000000000000000000011041365646035600162130ustar00rootroot00000000000000import {serial as test} from 'ava'; import delay from 'delay'; import getStdin from '.'; test('get stdin', async t => { process.stdin.isTTY = false; const promise = getStdin.buffer(); process.stdin.push(Buffer.from('uni')); process.stdin.push(Buffer.from('corns')); await delay(1); process.stdin.emit('end'); const data = await promise; t.true(data.equals(Buffer.from('unicorns'))); t.is(data.toString(), 'unicorns'); }); test('get empty buffer when no stdin', async t => { process.stdin.isTTY = true; t.true((await getStdin.buffer()).equals(Buffer.from(''))); }); get-stdin-8.0.0/test-real.js000066400000000000000000000002611365646035600156700ustar00rootroot00000000000000'use strict'; const getStdin = require('.'); (async () => { const stdin = await getStdin(); process.exit(stdin ? 0 : 1); // eslint-disable-line unicorn/no-process-exit })(); get-stdin-8.0.0/test.js000066400000000000000000000006771365646035600147620ustar00rootroot00000000000000import {serial as test} from 'ava'; import delay from 'delay'; import getStdin from '.'; test('get stdin', async t => { process.stdin.isTTY = false; const promise = getStdin(); process.stdin.push('uni'); process.stdin.push('corns'); await delay(1); process.stdin.emit('end'); t.is((await promise).trim(), 'unicorns'); }); test('get empty string when no stdin', async t => { process.stdin.isTTY = true; t.is(await getStdin(), ''); });