# Trans Functions

### Table of Contents

* [convert](#convert)
* [segmentLanguage](#segmentlanguage)
* [delimiteLanguage](#delimitelanguage)
* [normalizeDigits](#normalizedigits)

### convert

**Syntax**

```js
convert(text, codeFrom, codeTo);
```

**Description**

Converts the given text from one encoding to another.

**Parameters**

* `text` (string): The input text to be converted.
* `codeFrom` (string): The source encoding.
* `codeTo` (string): The target encoding.

**Returns**

* `string`: The converted text.

**Example**

```js
const text = "مرحبا";
const convertedText = convert(text, "utf", "tim");
console.log(convertedText); // "mrHbA"
```

### segmentLanguage

**Syntax**

```js
segmentLanguage(text);
```

**Description**

Segments the given text into Arabic and non-Arabic chunks.

**Parameters**

* `text` (string): The input text to be segmented.

**Returns**

* `Array`: An array of tuples, where the first element of each tuple is the language ("arabic" or "latin") and the second element is the corresponding text chunk.

**Example**

```js
const text = "Hello, مرحبا!";
const segmentedText = segmentLanguage(text);
console.log(segmentedText); // [[ 'latin', 'Hello, ' ], [ 'arabic', 'مرحبا!' ]]
```

### delimiteLanguage

**Syntax**

```js
delimiteLanguage(text, language, start, end);
```

**Description**

Wraps the text chunks of the specified language in the given start and end delimiters.

**Parameters**

* `text` (string): The input text to be delimited.
* `language` (string): The language to wrap ("arabic" or "latin").
* `start` (string): The start delimiter.
* `end` (string): The end delimiter.

**Returns**

* `string`: The text with specified language chunks wrapped in the delimiters.

**Example**

```js
const text = "Hello, مرحبا!";
const delimitedText = delimiteLanguage(text, "arabic", "<arabic>", "</arabic>");
console.log(delimitedText); // "Hello, <arabic>مرحبا</arabic>!"
```

### normalizeDigits

**Syntax**

```js
normalizeDigits(text, source, out);
```

**Description**

Normalizes the digits in the given text based on the source and target number systems.

**Parameters**

* `text` (string): The input text containing digits to be normalized.
* `source` (string): The source number system ("all", "west", "east", or "persian").
* `out` (string): The target number system ("west", "east", or "persian").

**Returns**

* `string`: The text with digits normalized.

**Example**

```js
const text = "١٢٣";
const normalizedDigits = normalizeDigits(text, "all", "west");
console.log(normalizedDigits); // "123"
```
