File tree 1 file changed +5
-2
lines changed
1 file changed +5
-2
lines changed Original file line number Diff line number Diff line change @@ -2,6 +2,8 @@ import stripAnsi from 'strip-ansi';
2
2
import { eastAsianWidth } from 'get-east-asian-width' ;
3
3
import emojiRegex from 'emoji-regex' ;
4
4
5
+ const segmenter = new Intl . Segmenter ( ) ;
6
+
5
7
export default function stringWidth ( string , options = { } ) {
6
8
if ( typeof string !== 'string' || string . length === 0 ) {
7
9
return 0 ;
@@ -21,8 +23,9 @@ export default function stringWidth(string, options = {}) {
21
23
}
22
24
23
25
let width = 0 ;
26
+ const eastAsianWidthOptions = { ambiguousAsWide : ! ambiguousIsNarrow } ;
24
27
25
- for ( const { segment : character } of new Intl . Segmenter ( ) . segment ( string ) ) {
28
+ for ( const { segment : character } of segmenter . segment ( string ) ) {
26
29
const codePoint = character . codePointAt ( 0 ) ;
27
30
28
31
// Ignore control characters
@@ -40,7 +43,7 @@ export default function stringWidth(string, options = {}) {
40
43
continue ;
41
44
}
42
45
43
- width += eastAsianWidth ( codePoint , { ambiguousAsWide : ! ambiguousIsNarrow } ) ;
46
+ width += eastAsianWidth ( codePoint , eastAsianWidthOptions ) ;
44
47
}
45
48
46
49
return width ;
You can’t perform that action at this time.
0 commit comments