@prantlf/get-stdin-with-tty
TypeScript icon, indicating that this package has built-in type declarations

6.0.1 • Public • Published

@prantlf/get-stdin-with-tty

NPM version Build Status

Get stdin as a string or buffer

This fork of the original project includes support for reading stdin from TTY, not only via pipes.

Install

$ npm install @prantlf/get-stdin-with-tty

Usage

// example.js
const getStdin = require('@prantlf/get-stdin-with-tty');

(async () => {
	console.log(await getStdin({ tty: true }));
	//=> 'unicorns'
})();
$ echo unicorns | node example.js
unicorns

API

Both methods returns a promise that is resolved when the end event fires on the stdin stream, indicating that there is no more data to be read.

getStdin([options])

Get stdin as a string.

In a TTY context, a promise that resolves to an empty string is returned, unless options.tty or getStdin.tty is true.

getStdin.buffer()

Get stdin as a Buffer.

In a TTY context, a promise that resolves to an empty Buffer is returned.

getStdin.tty = true/false

Set global TTY handling. When true, accepts input from TTY until a new line beginning with Ctrl-d or Ctrl-z (ASCII 04 and 26) is entered. (default = true)

When enabled for the example above:

$ node example.js
foobar
barfoo
^d
// =>
foobar
barfoo

Related

License

MIT © Sindre Sorhus © Moos © Ferdinand Prantl

Package Sidebar

Install

npm i @prantlf/get-stdin-with-tty

Weekly Downloads

0

Version

6.0.1

License

MIT

Unpacked Size

6.65 kB

Total Files

5

Last publish

Collaborators

  • prantlf