@@ -123,9 +123,9 @@ export function wordToLetters(word: string): string {
123123 * for linguistic, stylistic, or morphological reasons.
124124 *
125125 * @param {string } word - The Arabic word from which the affixes are to be removed.
126- * @returns {string } The word after removing any matching affixes. Returns the original word if no affix matches are found.
126+ * @returns {string } The word after removing any matching affixes. Returns the original word trimmed if no affix matches are found.
127127 */
128- export function removeArabicAffixes ( word : string ) : string {
128+ function removeArabicAffixesFromWord ( word : string ) : string {
129129 word = word . trim ( ) ;
130130 if ( ARABIC_PREFIXES . includes ( word . substring ( 0 , 2 ) ) ) {
131131 // For: ALEF & LAM
@@ -145,6 +145,23 @@ export function removeArabicAffixes(word: string): string {
145145 return word ;
146146}
147147
148+ /**
149+ * Removes predefined affixes (prefixes and suffixes) from an Arabic text if words start or end with those affixes.
150+ * This function is designed specifically for processing Arabic text, where certain affixes might need to be removed
151+ * for linguistic, stylistic, or morphological reasons.
152+ *
153+ * @param {string } text - The Arabic text from which the affixes are to be removed.
154+ * @returns {string } The text after removing any matching affixes from each word. Returns the original text trimmed if no affix matches are found.
155+ */
156+ export function removeArabicAffixes ( text : string ) : string {
157+ let new_sentence = '' ;
158+ text = text . trim ( ) ;
159+ for ( const word of text . split ( ' ' ) ) {
160+ new_sentence += removeArabicAffixesFromWord ( word ) + ' ' ;
161+ }
162+ return new_sentence . trim ( ) ;
163+ }
164+
148165/**
149166 * Calculates the encryption level based on the input level and word length.
150167 * @param {number } level - The input encryption level.
0 commit comments