demo Β· v143

Emoji segmenter

Unicode 16 added 8 new emoji groups including the face-with-bags-under-eyes, root vegetable, fingerprint, treble clef, and a new flag. The grapheme-cluster rules for these glyphs are non-trivial β€” they encode ZWJ joiners and skin-tone variants. Paste any text into the box and watch Intl.Segmenter split it into graphemes, words, and sentences correctly.

Live segmenter

Segments

Why ICU 77 matters here

  1. Each ICU upgrade ships updated grapheme-cluster rules. ICU 77 adds the segmentation tables for Unicode 16's new symbols.
  2. Pre-v143 browsers (on ICU 76 or older) split a U16 emoji into multiple "graphemes" β€” your str.length over-counts, you render half a glyph, your truncation cuts in the middle.
  3. Intl.Segmenter is the spec'd way to count human-perceived characters across locales. v143 has the right tables.
const seg = new Intl.Segmenter("en", { granularity: "grapheme" });
const count = [...seg.segment("πŸ‘¨β€πŸ‘©β€πŸ‘§β€πŸ‘¦πŸ‡¨πŸ‡­βœŠπŸΏ")].length;  // 3, not 19

see also