# rtl-text.js

An [Emscripten](https://github.com/kripken/emscripten) port of a subset of the functionality of [International Components for Unicode (ICU)](http://site.icu-project.org/). Supports the Arabic and Hebrew languages, which are written right-to-left.

## Using rtl-text

rtl-text exposes three functions:

### arabicShaping(input: string)
Takes an input string in "logical order" (i.e. characters in the order they are typed, not the order they will be displayed) and replaces Arabic characters with the "presentation form" of the character that represents the appropriate glyph based on the character's location within a word.

### processBidirectionalText(input: string): string
Takes an input string with characters in "logical order", along with a set of chosen line break points, and applies the [Unicode Bidirectional Algorithm](http://unicode.org/reports/tr9/) to the string. Returns a new line in "visual order" (i.e. characters in the order they are displayed, left-to-right). The algorithm will insert mandatory line breaks (`\n` etc.) if they are not already included in `lineBreakPoints`.

### processText(input: string): string
Combines `arabicShaping` and `processBidirectionalText` to process a string with both shaping and bidirectional processing.
Takes an input string with characters in "logical order", and applies the [Unicode Bidirectional Algorithm](http://unicode.org/reports/tr9/) to the string. Returns a new line with characters in "visual order" (i.e. characters in the order they are displayed, left-to-right) and replaces Arabic characters with the "presentation form" of the character that represents the appropriate glyph based on the character's location within a word.


## Example

```js
    const { arabicShaping, processBidirectionalText, processText } = require('rtl-text');
    // ES6: import rtlText from 'rtl-text'
    const text = 'سلام۳۹;
    const output = processText(text);
    console.log(output);
    // => '۳۹ﻡﻼﺳ'
```

## Build

1) Download and build ICU:
```sh
wget https://github.com/unicode-org/icu/releases/download/release-70-1/icu4c-70_1-src.tgz
tar xzf icu4c-70_1-src.tgz

cd icu/source

./runConfigureICU --help
./runConfigureICU MacOSX/GCC

make clean
make -j4
make install

```