Skip to content

Commit

Permalink
Require Node.js 10 (#31)
Browse files Browse the repository at this point in the history
  • Loading branch information
Ethan-Arrowood committed May 12, 2020
1 parent 99da4b5 commit 96ebc2e
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 40 deletions.
2 changes: 1 addition & 1 deletion .travis.yml
@@ -1,5 +1,5 @@
language: node_js
node_js:
- '14'
- '12'
- '10'
- '8'
58 changes: 20 additions & 38 deletions index.js
@@ -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
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

0 comments on commit 96ebc2e

Please sign in to comment.