Skip to content
This repository has been archived by the owner on Sep 11, 2020. It is now read-only.

[Deprecated] A JS implementation of the Unicode grapheme cluster breaking algorithm (UAX #29)

Notifications You must be signed in to change notification settings

yumetodo/grapheme-breaker-u10-0

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

49 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

grapheme-breaker-u10-0

Depecated

This libary is no longer maintained. Please use grapheme-breaker-mjs which is a fork library and supports Unicode 13.0.0.

See ufcpp/GraphemeSplitter#5 and taisukef/grapheme-breaker-mjs#2.

Build Status Greenkeeper badge

This is a fork of grapheme-breaker. Support Unicode 10.0 and emoji v5 by @vaskevich.

Please watch below before using this package.
grapheme-breaker#4

Original package is no longer maintained as far as I know. So, I republish this package.

Overveiw

A JavaScript implementation of the Unicode grapheme cluster breaking algorithm (UAX #29)

It is important to recognize that what the user thinks of as a “character”—a basic unit of a writing system for a language—may not be just a single Unicode code point. Instead, that basic unit may be made up of multiple Unicode code points. To avoid ambiguity with the computer use of the term character, this is called a user-perceived character. For example, “G” + acute-accent is a user-perceived character: users think of it as a single character, yet is actually represented by two Unicode code points. These user-perceived characters are approximated by what is called a grapheme cluster, which can be determined programmatically.

Installation

You can install via npm

npm install grapheme-breaker-u10-0

Example

var GraphemeBreaker = require('grapheme-breaker-u10-0');

// break a string into an array of grapheme clusters


GraphemeBreaker.break('Z͑ͫ̓ͪ̂ͫ̽͏̴̙̤̞͉͚̯̞̠͍A̴̵̜̰͔ͫ͗͢L̠ͨͧͩ͘G̴̻͈͍͔̹̑͗̎̅͛́Ǫ̵̹̻̝̳͂̌̌͘!͖̬̰̙̗̿̋ͥͥ̂ͣ̐́́͜͞') // => ['Z͑ͫ̓ͪ̂ͫ̽͏̴̙̤̞͉͚̯̞̠͍', 'A̴̵̜̰͔ͫ͗͢', 'L̠ͨͧͩ͘', 'G̴̻͈͍͔̹̑͗̎̅͛́', 'Ǫ̵̹̻̝̳͂̌̌͘', '!͖̬̰̙̗̿̋ͥͥ̂ͣ̐́́͜͞']


// or just count the number of grapheme clusters in a string


GraphemeBreaker.countBreaks('Z͑ͫ̓ͪ̂ͫ̽͏̴̙̤̞͉͚̯̞̠͍A̴̵̜̰͔ͫ͗͢L̠ͨͧͩ͘G̴̻͈͍͔̹̑͗̎̅͛́Ǫ̵̹̻̝̳͂̌̌͘!͖̬̰̙̗̿̋ͥͥ̂ͣ̐́́͜͞') // => 6


// use nextBreak and previousBreak to get break points starting
// from anywhere in the string
GraphemeBreaker.nextBreak('😜🇺🇸👍', 3) // => 6
GraphemeBreaker.previousBreak('😜🇺🇸👍', 3) // => 2

Development Notes

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.

  • The src/classes.coffee file is automatically generated from GraphemeBreakProperty.txt in the Unicode database by src/generate_data.coffee. 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 GraphemeBreakTest.txt and emoji-test.txt from the Unicode database, which is included in the repository for performance reasons while running them.

License

MIT

About

[Deprecated] A JS implementation of the Unicode grapheme cluster breaking algorithm (UAX #29)

Resources

Stars

Watchers

Forks

Packages

No packages published

Languages

  • CoffeeScript 100.0%