vlad 6f123ff03e 18.07 | 6 年之前 | |
---|---|---|
.. | ||
node_modules | 6 年之前 | |
index.js | 6 年之前 | |
license | 6 年之前 | |
package.json | 6 年之前 | |
readme.md | 6 年之前 |
Truncate a string to a specific width in the terminal
Gracefully handles ANSI escapes. Like a string styled with chalk
.
$ npm install --save cli-truncate
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…'
Type: string
Text to truncate.
Type: number
Columns to occupy in the terminal.
Type: string
Default: 'end'
Values: 'start'
, 'middle'
, 'end'
Position to truncate the string.
MIT © Sindre Sorhus