Skip to content
This repository was archived by the owner on Mar 8, 2023. It is now read-only.
/ cli-truncate Public archive
forked from sindresorhus/cli-truncate

Truncate a string to a specific width in the terminal

License

Notifications You must be signed in to change notification settings

devsbb/cli-truncate

This branch is 6 commits ahead of, 22 commits behind sindresorhus/cli-truncate:main.

Folders and files

NameName
Last commit message
Last commit date

Latest commit

300ac66 · May 11, 2017

History

14 Commits
May 11, 2017
May 11, 2017
May 11, 2017
May 11, 2017
Mar 11, 2016
Jan 13, 2017
May 11, 2017
May 11, 2017
Jan 13, 2017
May 11, 2017
Mar 11, 2016
May 11, 2017
May 11, 2017
Jan 13, 2017
May 11, 2017

Repository files navigation

cli-truncate Build Status

Truncate a string to a specific width in the terminal

ES5 compatible

Gracefully handles ANSI escapes. Like a string styled with chalk.

Install

$ npm install --save 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 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.

Related

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

License

MIT © Getgrover

About

Truncate a string to a specific width in the terminal

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • JavaScript 100.0%