💿Trans Functions

A set of functions to processing and converting Arabic text, including functions for language segmentation, and more.

Table of Contents

convert

Syntax

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

segmentLanguage

Syntax

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

delimiteLanguage

Syntax

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

normalizeDigits

Syntax

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

Last updated