tty-truncate
Truncate a string to the current text terminal width
const ttyTruncate = ; const str = '4724e053261747b278049de678b1ed'; processstdoutcolumns; //=> 30; //=> '4724e053261747b278049de678b1ed' processstdoutcolumns; //=> 20; //=> '4724e053261747b2780…'
Installation
npm install tty-truncate
API
const ttyTruncate = ;
ttyTruncate(input)
input: string
(single-line string)
Return: string
It replaces overflowing text with a single …
.
Note that this module works only when process.stdout.isTTY
is true
. In a non-TTY environment it always throws an error.
const ttyTruncate = ; console; try console; catch message console;
$ node example.js
> true
> example
$ node example.js | echo -n
> false
> tty-truncate doesn't support non-TTY environments.
License
ISC License © 2018 - 2019 Watanabe Shinnosuke