0.1.1 β’ Published 2 years ago
teinei-text-counter v0.1.1
teinei-text-counter
teinei-text-counter
is a minimal WebAssembly wrapper of the unicode-segmentation crate just for counting grapheme clusters. "δΈε―§"(teinei) means "careful" or "deliberate."
API
countGraphemeClusters(string)
Returns the length of a string with an extended grapheme cluster as a minimum unit.
import { countGraphemeClusters } from 'teinei-text-counter'
const text = 'πHelloπ©βπ©βπ§'
console.log(text.length)
//-> π 15
console.log(countGraphemeClusters(text))
//-> π 7
splitIntoGraphemeClusters(string)
Splits a string into extended grapheme clusters and returns as an array.
import { splitIntoGraphemeClusters } from 'teinei-text-counter'
const text = 'π©Έ½γγγγπ'
console.log(text.split(''))
//-> π ['\uD867', '\uDE3D', 'γ', 'γ', 'γ', 'γ', '\uD83D', '\uDE0B']
console.log(splitIntoGraphemeClusters(text))
//-> π ['π©Έ½', 'γ', 'γ', 'γ', 'γ', 'π']