Skip to content

graphemes

graphemes(value, locale?): string[]

Defined in: src/strings/random-string.ts:32

Split value into grapheme clusters — what a reader calls “characters”.

A flag or an emoji with a skin-tone modifier is several code points that display as one glyph; splitting on code points would break them apart. This exists to build an alphabet string can then draw from.

string

string

string[]

graphemes("👍🏽🎉"); // [ "👍🏽", "🎉" ], not four separate code points
string(5, graphemes("👍🏽🎉")); // a 5-emoji string, skin tones intact