artsy / emission

⚠️ Deprecated repo, moved to artsy/eigen ➑️ React Native Components
http://artsy.github.io/blog/2018/04/17/making-a-components-pod/
MIT License
618 stars 78 forks source link

[RFC] New dependency: grapheme-splitter #2072

Closed ds300 closed 4 years ago

ds300 commented 4 years ago

New Dependency

Name: grapheme-splitter URL: https://github.com/orling/grapheme-splitter

Focus

In JavaScript there is not always a one-to-one relationship between string characters and what a user would call a separate visual "letter". Some symbols are represented by several characters. This can cause issues when splitting strings and inadvertently cutting a multi-char letter in half, or when you need the actual number of letters in a string.

For example, emoji characters like "🌷","🎁","πŸ’©","😜" and "πŸ‘" are represented by two JavaScript characters each (high surrogate and low surrogate). That is,

"🌷".length == 2

The combined emoji are even longer:

"πŸ³οΈβ€πŸŒˆ".length == 6

We need to be able to tell the difference between a grapheme and a character when highlighting search results names. There is a unicode standard algorithm for breaking a string of characters into graphemes called UAX #29, and grapheme-splitter implements that standard.

Check List

Alternatives

No feasible alternatives except for having worse-quality text processing.

ds300 commented 4 years ago

OK going to resolve this. Thanks for the feedback folks :+1: