npm install grapheme-splitter
import GraphemeSplitter from 'grapheme-splitter'; // ES module
const GraphemeSplitter = require('grapheme-splitter'); // CommonJS
const splitter = new GraphemeSplitter();
const string = "🌷🎁💩😜👍🏳️🌈";
// string -> iterable iterator of grapheme clusters
const graphemesIt = splitter.iterateGraphemes(string);
[...graphemesIt], // [ '🌷', '🎁', '💩', '😜', '👍', '🏳️🌈' ]
[...graphemesIt], // [] (exhausted iterator)
splitter.splitGraphemes(string), // array of grapheme clusters
// [ '🌷', '🎁', '💩', '😜', '👍', '🏳️🌈' ]
splitter.countGraphemes(string), // 6 (count grapheme clusters)