File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change 55
66"use strict" ;
77
8- //------------------------------------------------------------------------------
9- // Requirements
10- //------------------------------------------------------------------------------
11-
12- const Graphemer = require ( "graphemer" ) . default ;
13-
148//------------------------------------------------------------------------------
159// Helpers
1610//------------------------------------------------------------------------------
1711
1812// eslint-disable-next-line no-control-regex -- intentionally including control characters
1913const ASCII_REGEX = / ^ [ \u0000 - \u007f ] * $ / u;
2014
21- /** @type {Graphemer | undefined } */
22- let splitter ;
15+ /** @type {Intl.Segmenter | undefined } */
16+ let segmenter ;
2317
2418//------------------------------------------------------------------------------
2519// Public Interface
@@ -47,11 +41,15 @@ function getGraphemeCount(value) {
4741 return value . length ;
4842 }
4943
50- if ( ! splitter ) {
51- splitter = new Graphemer ( ) ;
44+ segmenter ??= new Intl . Segmenter ( "en-US" ) ; // en-US locale should be supported everywhere
45+ let graphemeCount = 0 ;
46+
47+ // eslint-disable-next-line no-unused-vars -- for-of needs a variable
48+ for ( const unused of segmenter . segment ( value ) ) {
49+ graphemeCount ++ ;
5250 }
5351
54- return splitter . countGraphemes ( value ) ;
52+ return graphemeCount ;
5553}
5654
5755module . exports = {
Original file line number Diff line number Diff line change 8888 "file-entry-cache" : " ^8.0.0" ,
8989 "find-up" : " ^5.0.0" ,
9090 "glob-parent" : " ^6.0.2" ,
91- "graphemer" : " ^1.4.0" ,
9291 "ignore" : " ^5.2.0" ,
9392 "imurmurhash" : " ^0.1.4" ,
9493 "is-glob" : " ^4.0.0" ,
You can’t perform that action at this time.
0 commit comments