wallet-core/node_modules/cli-truncate
2017-12-27 19:34:16 +01:00
..
index.js add linting (and some initial fixes) 2017-05-28 00:40:43 +02:00
license node_modules 2017-08-14 05:02:09 +02:00
package.json node_modules 2017-08-14 05:02:09 +02:00
readme.md node_modules 2017-08-14 05:02:09 +02:00

cli-truncate Build Status

Truncate a string to a specific width in the terminal

Gracefully handles ANSI escapes. Like a string styled with chalk. It also supports Unicode surrogate pairs and fullwidth characters.

Install

$ npm install cli-truncate

Usage

const cliTruncate = require('cli-truncate');

cliTruncate('unicorn', 4);
//=> 'uni…'

// Truncate at different positions
cliTruncate('unicorn', 4, {position: 'start'});
//=> '…orn'

cliTruncate('unicorn', 4, {position: 'middle'});
//=> 'un…n'

cliTruncate('\u001B[31municorn\u001B[39m', 4);
//=> '\u001B[31muni\u001B[39m…'

// Truncate Unicode surrogate pairs
cliTruncate('uni\uD83C\uDE00corn', 5);
//=> 'uni\uD83C\uDE00…'

// Truncate fullwidth characters
cliTruncate('안녕하세요', 3);
//=> '안…'

// Truncate the paragraph to the terminal width
const paragraph = 'Lorem ipsum dolor sit amet, consectetuer adipiscing elit. Aenean commodo ligula eget dolor. Aenean massa.';
cliTruncate(paragraph, process.stdout.columns));
//=> 'Lorem ipsum dolor sit amet, consectetuer adipiscing…'

API

cliTruncate(input, columns, [options])

input

Type: string

Text to truncate.

columns

Type: number

Columns to occupy in the terminal.

options

Type: Object

position

Type: string
Default: end
Values: start middle end

Position to truncate the string.

  • wrap-ansi - Wordwrap a string with ANSI escape codes
  • slice-ansi - Slice a string with ANSI escape codes

License

MIT © Sindre Sorhus