📓Additional Functions

A set of functions to do many things

Table of Contents

hasShadda

Checks if a given word contains the shadda character.

Parameters

  • word (String): The word to be checked for the presence of shadda.

Returns

  • Boolean: true if the word contains shadda, false otherwise.

Example

const word = "مُتَحَدَّث";
console.log(hasShadda(word)); // Output: true

isVocalized

Checks if a given word contains any tashkeel (vocalization) characters, where the word can't contain spaces, digits and punctuation.

Parameters

  • word (String): The word to be checked for the presence of tashkeel.

Returns

  • Boolean: true if the word contains tashkeel, false otherwise.

Example

const word = "سَلَام";
console.log(isVocalized(word)); // Output: true

isVocalizedText

Checks if a given text contains any tashkeel (vocalization) characters, where the text can contain spaces, digits and punctuation.

Parameters

  • text (String): The text to be checked for the presence of tashkeel.

Returns

  • Boolean: true if the text contains tashkeel, false otherwise.

Example

const text = "هَذَا نَصٌّ مُشَكَّل";
console.log(isVocalizedText(text)); // Output: true

isArabicString

Checks if a given text does contain ONLY Arabic words, where the text can contain spaces, digits and punctuation.

Parameters

  • text (String): The text to be checked for Arabic words.

Returns

  • Boolean: true if the text does contain ONLY Arabic characters, false otherwise.

Example

const text = "مرحبا, world!";
console.log(isArabicString(text)); // Output: false

isArabicRange

Checks if a given word does contain ONLY Arabic characters, where the word can't contain spaces, digits and punctuation.

Parameters

  • text (String): The word to be checked for characters within the Arabic range.

Returns

  • Boolean: true if the word does contain Arabic characters, false otherwise.

Example

const text = "سلام";
console.log(isArabicRange(text)); // Output: true

isArabicWord

Checks if a given word is a valid Arabic word, where the word can't contain spaces, digits and punctuation, TEH_MARBUTA must be at the end.

Parameters

  • word (String): The word to be checked for validity.

Returns

  • Boolean: true if the word is a valid Arabic word, false otherwise.

Example

const word = "كَتَبَ";
console.log(isArabicWord(word)); // Output: true

separate

Separates the given Arabic word into letters and marks.

Parameters

  • word (String): The Arabic word to be separated.

  • extractShadda (Boolean): Optional, defaults to false. If set to true, the function will extract the Shadda character separately.

Returns

  • Array: An array of strings that contains the separated components. If extractShadda is set to false, the array will contain two elements: letters and marks. If extractShadda is set to true, the array will contain three elements: letters without shadda, marks, and shadda places.

Example

const word = "مُتَحَدَّث";
console.log(separate(word, true)); // Output: [ 'متحدث', 'ََُّ', '  ّ' ]

joint

Combines the given letters and marks to form an Arabic word.

Parameters

  • letters (String): The Arabic letters.

  • marks (String): The corresponding marks.

Returns

  • String: The combined Arabic word, or an empty string if the lengths of letters and marks are not equal.

Example

const letters = "متحدث";
const marks = "ََُّ";
console.log(joint(letters, marks)); // Output: مُتَحَدَّث

reduceTashkeel

Reduces unnecessary tashkeel (diacritic marks) from the given Arabic text.

Parameters

  • text (String): The Arabic text with tashkeel.

Returns

  • String: The Arabic text with reduced tashkeel.

Example

const text = "يَوْمَ الْخَمِيسَ";
console.log(reduceTashkeel(text)); // Output: يَوْم الخميس

fixSpaces

Fixes the spacing issues in the given Arabic text.

Parameters

  • text (String): The Arabic text with spacing issues.

Returns

  • String: The Arabic text with fixed spacing.

Example

const text = "هَذَا  نَصٌّ مُشَكَّل";
console.log(fixSpaces(text)); // Output: هَذَا نَصٌّ مُشَكَّل

autoCorrect

Automatically corrects common mistakes in the given Arabic text.

Parameters

  • text (String): The Arabic text with potential mistakes.

Returns

  • String: The corrected Arabic text.

spellit

Spells out the given Arabic word by returning a comma-separated list of character names.

Parameters

  • word (String): The Arabic word to be spelled out.

  • lang (String): Optional, defaults to 'ar'. The language of the character names, either 'ar' for Arabic or 'en' for English.

Returns

  • String: The spelled-out representation of the given word.

Example

const word = "سلام";
console.log(spellit(word)); // Output: سين, لام, ميم

Last updated