Get the visual width of a string - the number of columns required to display it
JavaScript
Switch branches/tags
Clone or download
Latest commit 74d8d55 Jul 18, 2017
Permalink
Failed to load latest commit information.
.editorconfig Meta tweaks May 9, 2017
.gitattributes ES2015ify and require Node.js 4 Sep 22, 2016
.gitignore Meta tweaks Jul 18, 2017
.npmrc Meta tweaks Jul 18, 2017
.travis.yml Meta tweaks Jun 26, 2017
index.js Meta tweaks Jul 18, 2017
license Meta tweaks Jun 26, 2017
package.json 2.1.1 Jul 18, 2017
readme.md Meta tweaks Jun 26, 2017
test.js Support combining characters (#12) Jul 18, 2017

readme.md

string-width Build Status

Get the visual width of a string - the number of columns required to display it

Some Unicode characters are fullwidth and use double the normal width. ANSI escape codes are stripped and doesn't affect the width.

Useful to be able to measure the actual width of command-line output.

Install

$ npm install string-width

Usage

const stringWidth = require('string-width');

stringWidth('');
//=> 2

stringWidth('\u001b[1m古\u001b[22m');
//=> 2

stringWidth('a');
//=> 1

Related

License

MIT © Sindre Sorhus