graphemes β
ts
function String.graphemes(target: string): Generator<string>Returns a generator that yields individual grapheme clusters from target string.
A grapheme cluster represents a single user-perceived character, which may consist of multiple Unicode code points (e.g., emojis with modifiers, base characters with combining diacriticals).
Example β
ts
import { String } from "@monstermann/string";
[...String.graphemes("hello")]; // ["h", "e", "l", "l", "o"]
[...String.graphemes("π¨βπ©βπ§βπ¦")]; // ["π¨βπ©βπ§βπ¦"]
[...String.graphemes("cafΓ©")]; // ["c", "a", "f", "Γ©"]
[...String.graphemes("ππ½")]; // ["ππ½"]
// Using in a loop
for (const grapheme of String.graphemes("helloπ")) {
console.log(grapheme); // "h", "e", "l", "l", "o", "π"
}ts
import { String } from "@monstermann/string";
[...pipe("hello", String.graphemes())]; // ["h", "e", "l", "l", "o"]
[...pipe("π¨βπ©βπ§βπ¦", String.graphemes())]; // ["π¨βπ©βπ§βπ¦"]
[...pipe("cafΓ©", String.graphemes())]; // ["c", "a", "f", "Γ©"]
[...pipe("ππ½", String.graphemes())]; // ["ππ½"]
// Using in a loop
for (const grapheme of pipe("helloπ", String.graphemes())) {
console.log(grapheme); // "h", "e", "l", "l", "o", "π"
}