-
-
Notifications
You must be signed in to change notification settings - Fork 28
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
99da4b5
commit 96ebc2e
Showing
3 changed files
with
22 additions
and
40 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,5 +1,5 @@ | ||
language: node_js | ||
node_js: | ||
- '14' | ||
- '12' | ||
- '10' | ||
- '8' |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
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); | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters