mirror of
https://github.com/vercel-labs/scriptc.git
synced 2026-11-01 07:33:12 +08:00
- TypedArray indexOf, lastIndexOf and includes on every element kind, typed
and checked-dynamic: strict equality (SameValueZero for includes) and
fromIndex as ToIntegerOrInfinity. A Buffer reached through a Uint8Array
value keeps Buffer's search.
- process.stdin 'readable' with read() and read(size), including sizes
above the read-ahead mark and input a once('readable') listener leaves
for a later 'data' listener. for await over process.stdin yields Buffers.
- Module bindings holding `new F()` of a constructor function can be read
and reassigned from other functions.
20 lines
559 B
JavaScript
20 lines
559 B
JavaScript
// process.stdin in paused mode through 'readable': each event drains the
|
|
// buffer with read(), one more event follows EOF, and 'end' comes after the
|
|
// read that finds the buffer empty.
|
|
const input = process.stdin;
|
|
const events = [];
|
|
let text = '';
|
|
input.on('readable', () => {
|
|
let reads = 0;
|
|
let chunk;
|
|
while ((chunk = input.read()) !== null) {
|
|
text += String(chunk);
|
|
reads++;
|
|
}
|
|
events.push(`readable ${reads}`);
|
|
});
|
|
input.on('end', () => {
|
|
console.log(events.join(', '));
|
|
console.log(JSON.stringify(text), input.readableLength);
|
|
});
|