Function segment

  • Return the user-perceived character segments of the given string, e.g.:

    const test = '๏ฌt๐Ÿš€๐Ÿ‘ซ๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ';
    console.log([...test]); // '["๏ฌ","t","๐Ÿš€","๐Ÿ‘ซ","๐Ÿ‘จ","โ€","๐Ÿ‘ฉ","โ€","๐Ÿ‘ง","โ€","๐Ÿ‘ฆ"]'
    console.log(segment(test)); // '["๏ฌ","t","๐Ÿš€","๐Ÿ‘ซ","๐Ÿ‘จโ€๐Ÿ‘ฉโ€๐Ÿ‘งโ€๐Ÿ‘ฆ"]'

    Note, this utility segments the string into grapheme clusters using Intl.Segmenter, a TC39 proposal which reached stage 4 in 2022, and may not be supported in older environments.


    • utf8: string

      the string for which to segment characters.

    Returns string[]

Generated using TypeDoc