Skip to content

Instantly share code, notes, and snippets.

@miyaokamarina
Created June 19, 2021 15:49
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save miyaokamarina/a9378b6b0434ecc921c878c043ddae76 to your computer and use it in GitHub Desktop.
Save miyaokamarina/a9378b6b0434ecc921c878c043ddae76 to your computer and use it in GitHub Desktop.
String length in Unicode grapheme clusters.
const segmenter = new Intl.Segmenter('en-us', {
granularity: 'grapheme',
});
const length = x => {
x = x.normalize('NFC');
const graphemes = segmenter.segment(x);
return Array.from(graphemes).length;
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment