Handle Unicode text, emoji, encoding, normalization, code points, and safe storage.
Lessons
Split text into user-perceived characters.
Intl.Segmenter for Graphemes is easiest to learn by reading the example, changing it, and observing the result.
const text = 'Hi👋🏽 family👨👩👧👦!';
// Wrong: counts UTF-16 code units, splits emoji
console.log(text.length);
// Right: count what the user perceives as characters
const seg = new Intl.Segmenter('en', { granularity: 'grapheme' });
const graphemes = [...seg.segment(text)].map(s => s.segment);
console.log(graphemes.length, graphemes);Practice the Intl.Segmenter for Graphemes example in a small scratch file, then explain what changed and why.