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
Terminal ANSI-aware string fit to fixed width:
$ npm install --save 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])
Where:
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 trancate.
Default: …
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"
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 © Roman Dvornov
1.0.0 (2015-09-02)
FAQs
Terminal ANSI-aware string fit to fixed width
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.