Data commit
This commit is contained in:
parent
7387c8f97b
commit
cb5bb5e222
199093 changed files with 3378972 additions and 0 deletions
25
Task/Input-loop/TypeScript/input-loop.ts
Normal file
25
Task/Input-loop/TypeScript/input-loop.ts
Normal file
|
|
@ -0,0 +1,25 @@
|
|||
#!/usr/bin/env node
|
||||
|
||||
import EventEmitter from 'events';
|
||||
|
||||
function stdinLineByLine() {
|
||||
const stdin = new EventEmitter();
|
||||
let buff = '';
|
||||
let lines;
|
||||
|
||||
process.stdin
|
||||
.on('data', (data) => {
|
||||
buff += data;
|
||||
lines = buff.split(/\r\n|\n/);
|
||||
buff = lines.pop();
|
||||
lines.forEach((line) => stdin.emit('line', line));
|
||||
})
|
||||
.on('end', () => {
|
||||
if (buff.length > 0) stdin.emit('line', buff);
|
||||
});
|
||||
|
||||
return stdin;
|
||||
}
|
||||
|
||||
const stdin = stdinLineByLine();
|
||||
stdin.on('line', console.log);
|
||||
Loading…
Add table
Add a link
Reference in a new issue