Skip to content

Require Node.js 10 #31

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
May 12, 2020
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .travis.yml
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
language: node_js
node_js:
- '14'
- '12'
- '10'
- '8'
58 changes: 20 additions & 38 deletions index.js
Original file line number Diff line number Diff line change
@@ -1,52 +1,34 @@
'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;
}

stdin.on('readable', () => {
let chunk;

while ((chunk = stdin.read())) {
result.push(chunk);
length += chunk.length;
}
});

stdin.on('end', () => {
resolve(Buffer.concat(result, length));
});
});
if (stdin.isTTY) {
return Buffer.concat([]);
}

for await (const chunk of stdin) {
result.push(chunk);
length += chunk.length;
}

return Buffer.concat(result, length);
};
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@
"url": "sindresorhus.com"
},
"engines": {
"node": ">=8"
"node": ">=10"
},
"scripts": {
"test": "xo && ava test.js test-buffer.js && echo unicorns | node test-real.js && tsd"
Expand Down