+33
| /// <reference types="node"/> | ||
| 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<string>; | ||
| /** | ||
| 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<Buffer>; | ||
| }; | ||
| export = getStdin; |
+10
-10
| 'use strict'; | ||
| const stdin = process.stdin; | ||
| const {stdin} = process; | ||
| module.exports = () => { | ||
| let ret = ''; | ||
| let result = ''; | ||
| return new Promise(resolve => { | ||
| if (stdin.isTTY) { | ||
| resolve(ret); | ||
| resolve(result); | ||
| return; | ||
@@ -19,3 +19,3 @@ } | ||
| while ((chunk = stdin.read())) { | ||
| ret += chunk; | ||
| result += chunk; | ||
| } | ||
@@ -25,3 +25,3 @@ }); | ||
| stdin.on('end', () => { | ||
| resolve(ret); | ||
| resolve(result); | ||
| }); | ||
@@ -32,4 +32,4 @@ }); | ||
| module.exports.buffer = () => { | ||
| const ret = []; | ||
| let len = 0; | ||
| const result = []; | ||
| let length = 0; | ||
@@ -46,4 +46,4 @@ return new Promise(resolve => { | ||
| while ((chunk = stdin.read())) { | ||
| ret.push(chunk); | ||
| len += chunk.length; | ||
| result.push(chunk); | ||
| length += chunk.length; | ||
| } | ||
@@ -53,5 +53,5 @@ }); | ||
| stdin.on('end', () => { | ||
| resolve(Buffer.concat(ret, len)); | ||
| resolve(Buffer.concat(result, length)); | ||
| }); | ||
| }); | ||
| }; |
+10
-6
| { | ||
| "name": "get-stdin", | ||
| "version": "6.0.0", | ||
| "version": "7.0.0", | ||
| "description": "Get stdin as a string or buffer", | ||
@@ -13,9 +13,10 @@ "license": "MIT", | ||
| "engines": { | ||
| "node": ">=4" | ||
| "node": ">=8" | ||
| }, | ||
| "scripts": { | ||
| "test": "xo && ava test.js test-buffer.js && echo unicorns | node test-real.js" | ||
| "test": "xo && ava test.js test-buffer.js && echo unicorns | node test-real.js && tsd" | ||
| }, | ||
| "files": [ | ||
| "index.js" | ||
| "index.js", | ||
| "index.d.ts" | ||
| ], | ||
@@ -33,5 +34,8 @@ "keywords": [ | ||
| "devDependencies": { | ||
| "ava": "*", | ||
| "xo": "*" | ||
| "@types/node": "^11.13.4", | ||
| "ava": "^1.4.1", | ||
| "delay": "^4.2.0", | ||
| "tsd": "^0.7.2", | ||
| "xo": "^0.24.0" | ||
| } | ||
| } |
+5
-5
@@ -19,6 +19,6 @@ # get-stdin [](https://travis-ci.org/sindresorhus/get-stdin) | ||
| getStdin().then(str => { | ||
| console.log(str); | ||
| (async () => { | ||
| console.log(await getStdin()); | ||
| //=> 'unicorns' | ||
| }); | ||
| })(); | ||
| ``` | ||
@@ -40,3 +40,3 @@ | ||
| In a TTY context, a promise that resolves to an empty string is returned. | ||
| In a TTY context, a promise that resolves to an empty `string` is returned. | ||
@@ -47,3 +47,3 @@ ### getStdin.buffer() | ||
| In a TTY context, a promise that resolves to an empty buffer is returned. | ||
| In a TTY context, a promise that resolves to an empty `Buffer` is returned. | ||
@@ -50,0 +50,0 @@ |
4546
29.77%5
25%66
60.98%5
150%