node_modules/eslint/lib/shared/string-utils.js in immosquare-cleaner-0.1.32 vs node_modules/eslint/lib/shared/string-utils.js in immosquare-cleaner-0.1.38

- old
+ new

@@ -4,24 +4,18 @@ */ "use strict"; //------------------------------------------------------------------------------ -// Requirements -//------------------------------------------------------------------------------ - -const Graphemer = require("graphemer").default; - -//------------------------------------------------------------------------------ // Helpers //------------------------------------------------------------------------------ // 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 //------------------------------------------------------------------------------ @@ -45,14 +39,18 @@ function getGraphemeCount(value) { if (ASCII_REGEX.test(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 = { upperCaseFirst, getGraphemeCount