Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/dotcypress/runes
✂️ Unicode-aware JS string splitting
https://github.com/dotcypress/runes
Last synced: 10 days ago
JSON representation
✂️ Unicode-aware JS string splitting
- Host: GitHub
- URL: https://github.com/dotcypress/runes
- Owner: dotcypress
- License: mit
- Created: 2016-08-19T16:43:54.000Z (about 8 years ago)
- Default Branch: develop
- Last Pushed: 2020-12-26T13:45:08.000Z (almost 4 years ago)
- Last Synced: 2024-10-14T14:18:50.582Z (28 days ago)
- Language: JavaScript
- Homepage:
- Size: 21.5 KB
- Stars: 226
- Watchers: 5
- Forks: 13
- Open Issues: 8
-
Metadata Files:
- Readme: readme.md
- License: LICENSE
Awesome Lists containing this project
README
# ✂️ Runes
[![NPM Version](https://img.shields.io/npm/v/runes.svg?style=flat-square)](https://www.npmjs.com/package/runes)
[![Build Status](https://img.shields.io/travis/dotcypress/runes.svg?branch=master&style=flat-square)](https://travis-ci.org/dotcypress/runes)> Unicode-aware JS string splitting with full Emoji support.
Split a string into its constituent characters, without munging emoji and other non-BMP code points.
## Why?
The native `String#split` implementation does not pay attention to [surrogate pairs](http://en.wikipedia.org/wiki/UTF-16). When the code units of a surrogate pair are split apart, they are not intelligible on their own. Unless they are put back together in the correct order, individual code units will cause problems in code that handles strings.
## Installation
```js
$ npm install runes
```## Example
```js
const runes = require('runes')// Standard String.split
'♥️'.split('') => ['♥', '️']
'Emoji 🤖'.split('') => ['E', 'm', 'o', 'j', 'i', ' ', '�', '�']
'👩👩👧👦'.split('') => ['�', '�', '', '�', '�', '', '�', '�', '', '�', '�']// ES6 string iterator
[...'♥️'] => [ '♥', '️' ]
[...'Emoji 🤖'] => [ 'E', 'm', 'o', 'j', 'i', ' ', '🤖' ]
[...'👩👩👧👦'] => [ '👩', '', '👩', '', '👧', '', '👦' ]// Runes
runes('♥️') => ['♥️']
runes('Emoji 🤖') => ['E', 'm', 'o', 'j', 'i', ' ', '🤖']
runes('👩👩👧👦') => ['👩👩👧👦']```
## Substring example
```js
const runes = require('runes')// String.substring
'👨👨👧👧a'.substring(1) => '�👨👧👧a'// Runes
runes.substr('👨👨👧👧a', 1) => 'a'```