# grapheme-breaker

> An implementation of the Unicode grapheme cluster breaking algorithm (UAX #29)

Latest version **0.3.2** (published 2015-11-16) · MIT license · 0 weekly downloads

## Install

```sh
npm install grapheme-breaker
pnpm add grapheme-breaker
yarn add grapheme-breaker
bun add grapheme-breaker
```

## Health

**Score 15/100 (F)** — status: abandoned.

Positive: no vulnerabilities.

Warnings: low downloads; no types; no esm support; pre 1.0.

Negative: abandoned; low maintenance score.

## Facts

| | |
|---|---|
| Version | 0.3.2 |
| Published | 2015-11-16 |
| First published | 2014-07-08 |
| Weekly downloads | 0 |
| License | MIT |
| TypeScript types | none |
| Module format | CommonJS |
| Dependencies | 2 |
| Known vulnerabilities | 0 |
| Install scripts | no |
| GitHub stars | 83 |
| Author | Devon Govett |
| Maintainers | devongovett |
| Keywords | unicode, text, break, segment, character, grapheme cluster |

## Links

- npm: https://www.npmjs.com/package/grapheme-breaker
- Repository: https://github.com/devongovett/grapheme-breaker
- Issues: https://github.com/devongovett/grapheme-breaker/issues
- npm.io page: https://npm.io/package/grapheme-breaker

## Dependencies (2)

- [brfs](https://npm.io/package/brfs.md) ^1.2.0
- [unicode-trie](https://npm.io/package/unicode-trie.md) ^0.3.1

## Alternatives

- [d3-force-3d](https://npm.io/package/d3-force-3d.md) — 1.0M weekly downloads
- [ng2-charts](https://npm.io/package/ng2-charts.md) — 486.8K weekly downloads
- [@arcgis/core](https://npm.io/package/@arcgis/core.md) — 257.8K weekly downloads
- [react-sparklines](https://npm.io/package/react-sparklines.md) — 249.3K weekly downloads
- [react-native-gifted-charts](https://npm.io/package/react-native-gifted-charts.md) — 182.3K weekly downloads

## Recent versions

- 0.3.2 (latest) — 2015-11-16
- 0.3.1 — 2015-09-19
- 0.2.0 — 2015-01-01
- 0.1.2 — 2014-07-14
- 0.1.1 — 2014-07-08

## README

# grapheme-breaker
A JavaScript implementation of the Unicode grapheme cluster breaking algorithm ([UAX #29](http://www.unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries))

> 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

## Example

```javascript
var GraphemeBreaker = require('grapheme-breaker');

// 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` from the Unicode database, which is included in the repository for performance
  reasons while running them.

## License

MIT

---
_Source: https://npm.io/package/grapheme-breaker · Machine-readable twin of the npm.io package page. Health data is recomputed on every publish._
