INNER CODE UNIT · TypeScript

wantsStdin

vinta/pangu.js · src/node/cli.ts:36

function wantsStdin(arg: string | undefined) {
  return arg === '-' || (arg === undefined && !process.stdin.isTTY);
}

// Reading has to be async: readFileSync(0) throws EAGAIN once a pipe carries more than a buffer or two. console.log() puts a trailing newline back, so dropping one here passes piped
// input through byte for byte
async function readStdin() {
  return (await text(process.stdin)).replace(/\n$/, '');
}

function spaceTextPrinted(text: string | undefined) {
  if (typeof text === 'string') {
    console.log(pangu.spaceText(text));
  } else {
    console.log(usage);
    process.exitCode = 1;
  }
}

View source record →

📰 Research Paper
Loading…
⏳ Fetching content…