UNPKG

804 BTypeScriptView Raw
1declare const stringLength: {
2 /**
3 Get the real length of a string - by correctly counting astral symbols and ignoring [ansi escape codes](https://github.com/sindresorhus/strip-ansi).
4
5 `String#length` errornously counts [astral symbols](https://web.archive.org/web/20150721114550/http://www.tlg.uci.edu/~opoudjis/unicode/unicode_astral.html) as two characters.
6
7 @example
8 ```
9 import stringLength = require('string-length');
10
11 '🐴'.length;
12 //=> 2
13
14 stringLength('🐴');
15 //=> 1
16
17 stringLength('\u001B[1municorn\u001B[22m');
18 //=> 7
19 ```
20 */
21 (string: string): number;
22
23 // TODO: Remove this for the next major release, refactor the whole definition to:
24 // declare function stringLength(string: string): number;
25 // export = stringLength;
26 default: typeof stringLength;
27};
28
29export = stringLength;