Nondeterministic Programming Methodology

npm

Need private packages and team management tools?Check out npm Orgs. »

tty-truncate

1.0.5 • Public • Published

tty-truncate

npm version GitHub Actions Coverage Status

Truncate a string to the current text terminal width

const ttyTruncate = require('tty-truncate');
 
const str = '4724e053261747b278049de678b1ed';
 
process.stdout.columns; //=> 30
ttyTruncate(str); //=> '4724e053261747b278049de678b1ed'
 
process.stdout.columns; //=> 20
ttyTruncate(str); //=> '4724e053261747b2780…'

Installation

Use npm.

npm install tty-truncate

API

const ttyTruncate = require('tty-truncate');

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 = require('tty-truncate');
 
console.log(process.stdout.isTTY === true);
 
try {
  console.log(ttyTruncate('example'));
} catch ({message}) {
  console.log(message);
}
$ 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

install

npm i tty-truncate

Downloadsweekly downloads

2,061

version

1.0.5

license

ISC

homepage

github.com

repository

Gitgithub

last publish

collaborators

  • avatar
Report a vulnerability