Installation
Quick Take
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 |
---|---|---|---|
str Type: String Obligatory: yes | |||
str | String | yes | The string in which you want to perform a search |
indexes Type: 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 |
---|---|---|---|
str Type: String Obligatory: yes | |||
str | String | yes | The string in which you want to perform a search |
indexes Type: 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
: