• Home
  • History
  • Annotate
Name Date Size #Lines LOC

..--

index.d.tsD24-Sep-2023792 305

index.jsD24-Sep-2023923 4831

licenseD24-Sep-20231.1 KiB105

package.jsonD24-Sep-2023941 5756

readme.mdD24-Sep-20231.4 KiB5132

readme.md

1# string-width
2
3> Get the visual width of a string - the number of columns required to display it
4
5Some Unicode characters are [fullwidth](https://en.wikipedia.org/wiki/Halfwidth_and_fullwidth_forms) and use double the normal width. [ANSI escape codes](https://en.wikipedia.org/wiki/ANSI_escape_code) are stripped and doesn't affect the width.
6
7Useful to be able to measure the actual width of command-line output.
8
9
10## Install
11
12```
13$ npm install string-width
14```
15
16
17## Usage
18
19```js
20const stringWidth = require('string-width');
21
22stringWidth('a');
23//=> 1
24
25stringWidth('古');
26//=> 2
27
28stringWidth('\u001B[1m古\u001B[22m');
29//=> 2
30```
31
32
33## Related
34
35- [string-width-cli](https://github.com/sindresorhus/string-width-cli) - CLI for this module
36- [string-length](https://github.com/sindresorhus/string-length) - Get the real length of a string
37- [widest-line](https://github.com/sindresorhus/widest-line) - Get the visual width of the widest line in a string
38
39
40---
41
42<div align="center">
43	<b>
44		<a href="https://tidelift.com/subscription/pkg/npm-string-width?utm_source=npm-string-width&utm_medium=referral&utm_campaign=readme">Get professional support for this package with a Tidelift subscription</a>
45	</b>
46	<br>
47	<sub>
48		Tidelift helps make open source sustainable for maintainers while giving companies<br>assurances about security, maintenance, and licensing for their dependencies.
49	</sub>
50</div>
51