2.0.0 • Published 4 years ago
graphemes v2.0.0
Graphemes
A JavaScript library to convert a string into an array of graphemes, following the Unicode 12 Text Segmentation spec
aka Unicode® Standard Annex #29
- Easy
String -> String[]
usage - Also handles streaming for huge text
- Iterator of code points in
- Iterator of graphemes out
- Passes the Unicode 12 grapheme test suite
- Straightforward, Modern Typescript implementation
- Zero dependencies!
Usage
npm i graphemes
- This code uses Unicode property escapes so be sure to include
@babel/plugin-proposal-unicode-property-regex
if you plan to target Firefox and Edge. Example here
Example
const graphemes = require('graphemes');
const text = '각กำg̈';
console.log('Code points:', Array.from(text));
console.log('Graphemes:', graphemes.default(text));
/*
Code points: ['ᄀ', 'ᅡ', 'ᆨ','ก', 'ำ', 'g','̈']
Graphemes: [ '각', 'กำ', 'g̈' ]
*/