Last active
October 16, 2021 19:15
-
-
Save comame/db013cc689954ef77c546872aa1f6fd1 to your computer and use it in GitHub Desktop.
stdin-reader
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
function*stdinIter(){const t=require("fs").readFileSync("/dev/stdin","utf-8").trim().split(/\n|\s/);yield*t}function readMany(t,e){const i=e||this.iter||(this.iter=stdinIter()),n=[];for(let e=0;e<t;e+=1)n.push(i.next().value);return n}; | |
const DEBUG = process.env.DEBUG | |
function test(...msg) { | |
if (DEBUG) console.log(...msg) | |
} | |
// const [ a, b, c ] = readMany(3) | |
(() => { | |
// code | |
})() | |
// cat $1 | DEBUG=1 node $1.js |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment