npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

@editablejs/breaker

v1.0.0

Published

A JavaScript (ES Module) implementation for web apps, Deno and Node.js of the Unicode 14.0.0 grapheme cluster breaking algorithm ([UAX #29](http://www.unicode.org/reports/tr29/#Grapheme_Cluster_Boundaries))

Downloads

972

Readme

grapheme-breaker

A JavaScript (ES Module) implementation for web apps, Deno and Node.js of the Unicode 14.0.0 grapheme cluster breaking algorithm (UAX #29)

This is a fork of grapheme-breaker-mjs. Support Unicode 13.0 and emoji v5 by @taisukef(publishd by @taisukef). Support Unicode 10.0 and emoji v5 by @vaskevich(publishd by @yumetodo).
The base project is grapheme-breaker by @devongovett

for Web and Deno

test page
https://taisukef.github.io/grapheme-breaker-mjs/

import { breaks } from '@editablejs/breaker';

console.log(breaks('😜🇺🇸👍')); // => [ '😜', '🇺🇸', '👍' ]

Installation

You can install via npm

npm i @editablejs/-reaker

Example

import { breaks, countBreaks, nextBreak, previousBreak } from '@editablejs/breaker'

// break a string into an array of grapheme clusters


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


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


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


// use nextBreak and previousBreak to get break points starting
// from anywhere in the string
nextBreak('😜🇺🇸👍', 3) // => 6
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.ts file is generated from GraphemeBreakProperty.txt in the Unicode database by src/generate_data.ts. 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 pnpm test. They are written using jest, 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