> For the complete documentation index, see [llms.txt](https://mdanok.gitbook.io/arajs/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://mdanok.gitbook.io/arajs/trans-functions.md).

# 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"
```


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://mdanok.gitbook.io/arajs/trans-functions.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
