get-stdin
Advanced tools
Comparing version 7.0.0 to 8.0.0
54
index.js
'use strict'; | ||
const {stdin} = process; | ||
module.exports = () => { | ||
module.exports = async () => { | ||
let result = ''; | ||
return new Promise(resolve => { | ||
if (stdin.isTTY) { | ||
resolve(result); | ||
return; | ||
} | ||
if (stdin.isTTY) { | ||
return result; | ||
} | ||
stdin.setEncoding('utf8'); | ||
stdin.setEncoding('utf8'); | ||
stdin.on('readable', () => { | ||
let chunk; | ||
for await (const chunk of stdin) { | ||
result += chunk; | ||
} | ||
while ((chunk = stdin.read())) { | ||
result += chunk; | ||
} | ||
}); | ||
stdin.on('end', () => { | ||
resolve(result); | ||
}); | ||
}); | ||
return result; | ||
}; | ||
module.exports.buffer = () => { | ||
module.exports.buffer = async () => { | ||
const result = []; | ||
let length = 0; | ||
return new Promise(resolve => { | ||
if (stdin.isTTY) { | ||
resolve(Buffer.concat([])); | ||
return; | ||
} | ||
if (stdin.isTTY) { | ||
return Buffer.concat([]); | ||
} | ||
stdin.on('readable', () => { | ||
let chunk; | ||
for await (const chunk of stdin) { | ||
result.push(chunk); | ||
length += chunk.length; | ||
} | ||
while ((chunk = stdin.read())) { | ||
result.push(chunk); | ||
length += chunk.length; | ||
} | ||
}); | ||
stdin.on('end', () => { | ||
resolve(Buffer.concat(result, length)); | ||
}); | ||
}); | ||
return Buffer.concat(result, length); | ||
}; |
{ | ||
"name": "get-stdin", | ||
"version": "7.0.0", | ||
"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": "sindresorhus.com" | ||
"url": "https://sindresorhus.com" | ||
}, | ||
"engines": { | ||
"node": ">=8" | ||
"node": ">=10" | ||
}, | ||
@@ -33,8 +34,8 @@ "scripts": { | ||
"devDependencies": { | ||
"@types/node": "^11.13.4", | ||
"ava": "^1.4.1", | ||
"@types/node": "^13.13.5", | ||
"ava": "^2.4.0", | ||
"delay": "^4.2.0", | ||
"tsd": "^0.7.2", | ||
"tsd": "^0.11.0", | ||
"xo": "^0.24.0" | ||
} | ||
} |
@@ -1,6 +0,5 @@ | ||
# get-stdin [![Build Status](https://travis-ci.org/sindresorhus/get-stdin.svg?branch=master)](https://travis-ci.org/sindresorhus/get-stdin) | ||
# 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 | ||
@@ -12,3 +11,2 @@ | ||
## Usage | ||
@@ -31,3 +29,2 @@ | ||
## API | ||
@@ -49,3 +46,2 @@ | ||
## Related | ||
@@ -55,5 +51,12 @@ | ||
--- | ||
## License | ||
MIT © [Sindre Sorhus](https://sindresorhus.com) | ||
<div align="center"> | ||
<b> | ||
<a href="https://tidelift.com/subscription/pkg/npm-get-stdin?utm_source=npm-get-stdin&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a> | ||
</b> | ||
<br> | ||
<sub> | ||
Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies. | ||
</sub> | ||
</div> |
Sorry, the diff of this file is not supported yet
4706
59
50