This package is retired. The published package, documentation, examples, and changelog remain available.
Retirement
This package has been retired and is no longer maintained.
The API documentation below is archived. Archived examples, the changelog, and the published package on npm remain available.
Idea
Native JS string index system is not based on grapheme count — while “a” length is one, emoji “🧢” is two-character-long, because it’s two characters actually, \uD83E and \uDDE2.
In ideal world, JS string index system would count emoji as one character-long. That’s so-called grapheme-based index system. Letter “a” and cap emoji “🧢” are both graphemes.
This program is a converter that converts between the two systems, it’s based on grapheme-splitter.
API — nativeToUnicode()
It converts JS native indexes to indexes (used in let’s say String.slice()), based on grapheme count.
The function nativeToUnicode() is imported like this:
It’s a function which takes two input arguments:
| Input argument | Type | Obligatory | Description |
|---|---|---|---|
strType: String Obligatory: yes | |||
str | String | yes | The string in which you want to perform a search |
indexesType: Whatever Obligatory: yes | |||
indexes | Whatever | yes | Normally a natural number or zero but it can be numeric string or nested AST of thereof. |
The function will return a clone of the same data structure as indexes, but with digits converted.
API — unicodeToNative()
It converts grapheme count-based indexes to JS native indexes.
The function unicodeToNative() is imported like this:
It’s a function which takes two input arguments:
| Input argument | Type | Obligatory | Description |
|---|---|---|---|
strType: String Obligatory: yes | |||
str | String | yes | The string in which you want to perform a search |
indexesType: Whatever Obligatory: yes | |||
indexes | Whatever | yes | Normally a natural number or zero but it can be numeric string or nested AST of thereof. |
The function will return a clone of the same data structure as indexes, but with digits converted.
API — version
You can import version: