Skip to content

A JavaScript library to convert a string into an array of graphemes, following the Unicode 12 Text Segmentation spec

License

Notifications You must be signed in to change notification settings

tomcumming/Graphemes

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

24 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

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̈' ]
*/

About

A JavaScript library to convert a string into an array of graphemes, following the Unicode 12 Text Segmentation spec

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published