Security News
Weekly Downloads Now Available in npm Package Search Results
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
fixed-width-string
Advanced tools
Fit a string to the fixed width (length) with aware of ANSI escape codes.
Features:
$ npm install fixed-width-string
var fixedWidthString = require('fixed-width-string');
console.log(fixedWidthString('test', 10));
// "test "
console.log(fixedWidthString('very long string', 10));
// "very long…"
console.log(fixedWidthString('very long string', { align: 'right' }));
// "…ng string"
var chalk = require('chalk');
console.log(fixedWidthString(chalk.green('hello') + ' ' + chalk.red('world'), 8));
// "\u001b[32mhello\u001b[39m \u001b[31mw…\u001b[39m"
//
// but in terminal you'll see colored
// "hello w…"
fixedWidthString(str, width[, options])
String to padding with.
Default: ' '
(one space)
console.log(fixedWidthString('test', 10));
// "test "
console.log(fixedWidthString('test', 10, { padding: '.' }));
// "test......"
Side to align.
Values: 'left'
or 'right'
Default: 'left'
console.log(fixedWidthString('test', 10));
// "test "
console.log(fixedWidthString('test', 10, { align: 'right' }));
// " test"
String to be placed when string is truncating.
Default: '…'
Note: To omit ellipsis, pass an empty string or falsy value for the option.
console.log(fixedWidthString('hello world', 8));
// "hello w…"
console.log(fixedWidthString('hello world', 8, { ellipsis: '~' }));
// "hello w~"
console.log(fixedWidthString('hello world', 8, { ellipsis: '...', align: 'right' }));
// "...world"
console.log(fixedWidthString('hello world', 8, { ellipsis: false, align: 'right' }));
// "lo world"
Side should be truncated.
Values: 'left'
or 'right'
Default: 'right'
when align: 'left'
or 'left'
when align: 'right'
console.log(fixedWidthString('hello world', 8));
// "hello w…"
console.log(fixedWidthString('hello world', 8, { truncate: 'left' }));
// "…o world"
console.log(fixedWidthString('hello world', 8, { align: 'right' }));
// "hello w…"
console.log(fixedWidthString('hello world', 8, { align: 'right', truncate: 'left' }));
// "…o world"
MIT
2.0.0 (2020-05-15)
FAQs
Terminal ANSI-aware string fit to fixed width
The npm package fixed-width-string receives a total of 2,163 weekly downloads. As such, fixed-width-string popularity was classified as popular.
We found that fixed-width-string demonstrated a not healthy version release cadence and project activity because the last version was released a year ago. It has 1 open source maintainer collaborating on the project.
Did you know?
Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.
Security News
Socket's package search now displays weekly downloads for npm packages, helping developers quickly assess popularity and make more informed decisions.
Security News
A Stanford study reveals 9.5% of engineers contribute almost nothing, costing tech $90B annually, with remote work fueling the rise of "ghost engineers."
Research
Security News
Socket’s threat research team has detected six malicious npm packages typosquatting popular libraries to insert SSH backdoors.