pax_global_header 0000666 0000000 0000000 00000000064 13656460356 0014530 g ustar 00root root 0000000 0000000 52 comment=07288e101242054df3c197abc5559458af6c78ba
get-stdin-8.0.0/ 0000775 0000000 0000000 00000000000 13656460356 0013433 5 ustar 00root root 0000000 0000000 get-stdin-8.0.0/.editorconfig 0000664 0000000 0000000 00000000257 13656460356 0016114 0 ustar 00root root 0000000 0000000 root = 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/.gitattributes 0000664 0000000 0000000 00000000023 13656460356 0016321 0 ustar 00root root 0000000 0000000 * text=auto eol=lf
get-stdin-8.0.0/.github/ 0000775 0000000 0000000 00000000000 13656460356 0014773 5 ustar 00root root 0000000 0000000 get-stdin-8.0.0/.github/funding.yml 0000664 0000000 0000000 00000000163 13656460356 0017150 0 ustar 00root root 0000000 0000000 github: sindresorhus
open_collective: sindresorhus
tidelift: npm/get-stdin
custom: https://sindresorhus.com/donate
get-stdin-8.0.0/.github/security.md 0000664 0000000 0000000 00000000263 13656460356 0017165 0 ustar 00root root 0000000 0000000 # 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/.gitignore 0000664 0000000 0000000 00000000027 13656460356 0015422 0 ustar 00root root 0000000 0000000 node_modules
yarn.lock
get-stdin-8.0.0/.npmrc 0000664 0000000 0000000 00000000023 13656460356 0014546 0 ustar 00root root 0000000 0000000 package-lock=false
get-stdin-8.0.0/.travis.yml 0000664 0000000 0000000 00000000066 13656460356 0015546 0 ustar 00root root 0000000 0000000 language: node_js
node_js:
- '14'
- '12'
- '10'
get-stdin-8.0.0/index.d.ts 0000664 0000000 0000000 00000001611 13656460356 0015333 0 ustar 00root root 0000000 0000000 ///
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.js 0000664 0000000 0000000 00000000761 13656460356 0015104 0 ustar 00root root 0000000 0000000 '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.ts 0000664 0000000 0000000 00000000232 13656460356 0016306 0 ustar 00root root 0000000 0000000 import {expectType} from 'tsd';
import getStdin = require('.');
expectType>(getStdin());
expectType>(getStdin.buffer());
get-stdin-8.0.0/license 0000664 0000000 0000000 00000002135 13656460356 0015001 0 ustar 00root root 0000000 0000000 MIT 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.json 0000664 0000000 0000000 00000001366 13656460356 0015727 0 ustar 00root root 0000000 0000000 {
"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.md 0000664 0000000 0000000 00000002625 13656460356 0015217 0 ustar 00root root 0000000 0000000 # get-stdin [](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-stdin-8.0.0/test-buffer.js 0000664 0000000 0000000 00000001104 13656460356 0016213 0 ustar 00root root 0000000 0000000 import {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.js 0000664 0000000 0000000 00000000261 13656460356 0015670 0 ustar 00root root 0000000 0000000 '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.js 0000664 0000000 0000000 00000000677 13656460356 0014762 0 ustar 00root root 0000000 0000000 import {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(), '');
});