Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: switch grapheme-splitter to graphemer #17160

Merged
merged 4 commits into from May 8, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
6 changes: 3 additions & 3 deletions lib/shared/string-utils.js
Expand Up @@ -9,7 +9,7 @@
// Requirements
//------------------------------------------------------------------------------

const GraphemeSplitter = require("grapheme-splitter");
const Graphemer = require("graphemer").default;

//------------------------------------------------------------------------------
// Helpers
Expand All @@ -18,7 +18,7 @@ const GraphemeSplitter = require("grapheme-splitter");
// eslint-disable-next-line no-control-regex -- intentionally including control characters
const ASCII_REGEX = /^[\u0000-\u007f]*$/u;

/** @type {GraphemeSplitter | undefined} */
/** @type {Graphemer | undefined} */
let splitter;

//------------------------------------------------------------------------------
Expand Down Expand Up @@ -48,7 +48,7 @@ function getGraphemeCount(value) {
}

if (!splitter) {
splitter = new GraphemeSplitter();
splitter = new Graphemer();
}

return splitter.countGraphemes(value);
Expand Down
2 changes: 1 addition & 1 deletion package.json
Expand Up @@ -83,7 +83,7 @@
"find-up": "^5.0.0",
"glob-parent": "^6.0.2",
"globals": "^13.19.0",
"grapheme-splitter": "^1.0.4",
"graphemer": "^1.4.0",
"ignore": "^5.2.0",
"import-fresh": "^3.0.0",
"imurmurhash": "^0.1.4",
Expand Down
3 changes: 2 additions & 1 deletion tests/lib/shared/string-utils.js
Expand Up @@ -76,7 +76,8 @@ describe("getGraphemeCount", () => {
"πŸ‘¨β€πŸ‘©β€πŸ‘¦aπŸ‘¨β€πŸ‘©β€πŸ‘¦": 3,
"aπŸ‘¨β€πŸ‘©β€πŸ‘¦bπŸ‘¨β€πŸ‘©β€πŸ‘¦c": 5,
"πŸ‘¨β€πŸ‘©β€πŸ‘¦πŸ‘": 2,
"πŸ‘ΆπŸ½πŸ‘¨β€πŸ‘©β€πŸ‘¦": 2
"πŸ‘ΆπŸ½πŸ‘¨β€πŸ‘©β€πŸ‘¦": 2,
"πŸ‘©β€πŸ¦°πŸ‘©β€πŸ‘©β€πŸ‘¦β€πŸ‘¦πŸ³οΈβ€πŸŒˆ": 3 // 3 grapheme, 14 code points, 22 code units
};
/* eslint-enable quote-props -- Make consistent here for readability */

Expand Down