diff --git a/lib/shared/string-utils.js b/lib/shared/string-utils.js index ed0781e578c..31d0df982ca 100644 --- a/lib/shared/string-utils.js +++ b/lib/shared/string-utils.js @@ -5,12 +5,6 @@ "use strict"; -//------------------------------------------------------------------------------ -// Requirements -//------------------------------------------------------------------------------ - -const Graphemer = require("graphemer").default; - //------------------------------------------------------------------------------ // Helpers //------------------------------------------------------------------------------ @@ -18,8 +12,8 @@ const Graphemer = require("graphemer").default; // eslint-disable-next-line no-control-regex -- intentionally including control characters const ASCII_REGEX = /^[\u0000-\u007f]*$/u; -/** @type {Graphemer | undefined} */ -let splitter; +/** @type {Intl.Segmenter | undefined} */ +let segmenter; //------------------------------------------------------------------------------ // Public Interface @@ -47,11 +41,15 @@ function getGraphemeCount(value) { return value.length; } - if (!splitter) { - splitter = new Graphemer(); + segmenter ??= new Intl.Segmenter("en-US"); // en-US locale should be supported everywhere + let graphemeCount = 0; + + // eslint-disable-next-line no-unused-vars -- for-of needs a variable + for (const unused of segmenter.segment(value)) { + graphemeCount++; } - return splitter.countGraphemes(value); + return graphemeCount; } module.exports = { diff --git a/package.json b/package.json index 366974e51b2..8a88f66ade7 100644 --- a/package.json +++ b/package.json @@ -88,7 +88,6 @@ "file-entry-cache": "^8.0.0", "find-up": "^5.0.0", "glob-parent": "^6.0.2", - "graphemer": "^1.4.0", "ignore": "^5.2.0", "imurmurhash": "^0.1.4", "is-glob": "^4.0.0",