UNPKG

554 BTypeScriptView Raw
1/**
2Get the visual width of a string - the number of columns required to display it.
3
4Some 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.
5
6@example
7```
8import stringWidth from 'string-width';
9
10stringWidth('a');
11//=> 1
12
13stringWidth('古');
14//=> 2
15
16stringWidth('\u001B[1m古\u001B[22m');
17//=> 2
18```
19*/
20export default function stringWidth(string: string): number;