Coder Social home page Coder Social logo

graphemesplit's Introduction

graphemesplit

npm version

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

Installation

npm install graphemesplit

How to use

const split = require('graphemesplit')

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

Author

Nao Yonashiro(@orisano)

License

MIT

References

foliojs/grapheme-breaker

Unicode® Standard Annex #29

GraphemeBreakProperty.txt

GraphemeBreakTest.txt

emoji-data.txt

graphemesplit's People

Contributors

ethanrutherford avatar ivansanchez avatar ka2jun8 avatar linonetwo avatar orisano avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar

graphemesplit's Issues

Iterator-based API

It would be useful if this library could expose an API for lazily splitting a string into graphemes, both forwards and backwards, based on the Iterable/Iterator protocols. This would avoid processing a whole string, which could potentially be large, for simple tasks like finding the last grapheme.

Run in browser enviros

Feature request: allow this to run in browser environments.

Even though the code is a commonJS module with require()s, I'm trying to run this in a web browser after applying some RollupJS/Webpack magic.

The main roadblock is that right now the code uses Buffer, but Buffer is not defined in web browsers.

Replacing Buffer with Uint8Array (which is defined in web browsers and behaves like a nodejs Buffer) should make things work without too much work.

Make graphemesplit compatible with React Native

Hi! 👋

Firstly, thanks for your work on this project! 🙂

Today I used patch-package to patch [email protected] for the project I'm working on.

On React Native I got this error: Buffer undefined

Here is the diff that solved my problem:

diff --git a/node_modules/graphemesplit/index.js b/node_modules/graphemesplit/index.js
index e5c7827..6f5652c 100644
--- a/node_modules/graphemesplit/index.js
+++ b/node_modules/graphemesplit/index.js
@@ -1,6 +1,7 @@
 const types = require("./types");
 const typeTrieData = require("./typeTrie.json").data;
 const extPictData = require("./extPict.json").data;
+global.Buffer = global.Buffer || require("buffer").Buffer;
 
 const UnicodeTrie = require("unicode-trie");
 

This issue body was partially generated by patch-package.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.