console // => [ '😜', '🇺🇸', '👍' ]
You can install via npm
npm i grapheme-breaker-mjs
// break a string into an array of grapheme clustersGraphemeBreaker // => ['Z͑ͫ̓ͪ̂ͫ̽͏̴̙̤̞͉͚̯̞̠͍', 'A̴̵̜̰͔ͫ͗͢', 'L̠ͨͧͩ͘', 'G̴̻͈͍͔̹̑͗̎̅͛́', 'Ǫ̵̹̻̝̳͂̌̌͘', '!͖̬̰̙̗̿̋ͥͥ̂ͣ̐́́͜͞']// or just count the number of grapheme clusters in a stringGraphemeBreaker // => 6// use nextBreak and previousBreak to get break points starting// from anywhere in the stringGraphemeBreaker // => 6GraphemeBreaker // => 2
In order to use the library, you shouldn't need to know this, but if you're interested in contributing or fixing bugs, these things might be of interest.
src/classes.mjsfile is generated from
GraphemeBreakProperty.txtin the Unicode database by
src/generate_data.mjs. It should be rare that you need to run this, but you may if, for instance, you want to change the Unicode version.
- You can run the tests using
npm test. They are written using
mocha, and generated from
emoji-test.txtfrom the Unicode database, which is included in the repository for performance reasons while running them.