๐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:
trueif the word contains shadda,falseotherwise.
Example
const word = "ู
ูุชูุญูุฏููุซ";
console.log(hasShadda(word)); // Output: trueisVocalized
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:
trueif the word contains tashkeel,falseotherwise.
Example
const word = "ุณูููุงู
";
console.log(isVocalized(word)); // Output: trueisVocalizedText
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:
trueif the text contains tashkeel,falseotherwise.
Example
const text = "ููุฐูุง ููุตูู ู
ูุดููููู";
console.log(isVocalizedText(text)); // Output: trueisArabicString
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:
trueif the text does contain ONLY Arabic characters,falseotherwise.
Example
const text = "ู
ุฑุญุจุง, world!";
console.log(isArabicString(text)); // Output: falseisArabicRange
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:
trueif the word does contain Arabic characters,falseotherwise.
Example
const text = "ุณูุงู
";
console.log(isArabicRange(text)); // Output: trueisArabicWord
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:
trueif the word is a valid Arabic word,falseotherwise.
Example
const word = "ููุชูุจู";
console.log(isArabicWord(word)); // Output: trueseparate
Separates the given Arabic word into letters and marks.
Parameters
word(String): The Arabic word to be separated.extractShadda(Boolean): Optional, defaults tofalse. If set totrue, the function will extract the Shadda character separately.
Returns
Array: An array of strings that contains the separated components. If
extractShaddais set tofalse, the array will contain two elements: letters and marks. IfextractShaddais set totrue, 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
lettersandmarksare 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