es-tooling / ecosystem-cleanup

A place to keep track of ongoing efforts to clean up the JS ecosystem
405 stars 2 forks source link

Replace `graphemer` and `grapheme-splitter` with `Intl.Segmenter` #70

Closed cometkim closed 1 week ago

cometkim commented 3 months ago

graphemer (22M weekly downloads on NPM) and grapheme-splitter (6M weekly downloads on NPM) are both for handling grapheme clusters (for counting the length of a Unicode text). But they're outdated, unmaintained for a long time.

The JavaScript's Intl.Segmenter API can replace those packages completely, and is supported by most modern browsers/Node.js/Deno/Bun.

However, it might not be supported in older versions of browsers or some environments like React Native (Hermes). I created unicode-segmenter for those cases. It's compatible with the latest version of the Unicode specification, is way small, and is way performant.

43081j commented 3 months ago

makes sense to me 👍

i think we'd add it to the preferred manifest so we can document the fact there are two solutions (a native one for newer nodes, and a package for older ones). we can just list them as two alternatives

cometkim commented 2 weeks ago

Yo, I recently update the unicode-segmenter, it now has 13% size of graphemer, 1/3 even when gzipped.

Do I need to make a PR to the module-replacements or something? Please let me know if I can help

43081j commented 2 weeks ago

Yes please

You would create a pr in the replacements repo which adds an entry to the preferred manifest (a JSON file). Then add some docs

If you look at any previous pr, you'll quickly understand what to do I think