Skip to main content
Detect Arabic script in input. Useful for routing multilingual content to the right NLP pipeline or separating Arabic from Persian (Farsi) input.

Functions

isArabic(str, trimPattern?)

Returns true when all characters of str (after trimming) are in the Arabic Unicode block and match contextual Arabic letterforms.

Parameters

hasArabic(str)

Returns true when str contains at least one Arabic character.

Persian vs. Arabic

Persian uses the Arabic script plus پ چ ژ گ plus different code points for ya/kaf. Two practical consequences:
  1. A pure Persian string typed on a Persian keyboard also passes isArabic — the characters all fall in U+0600–U+06FF.
  2. A pure Arabic string fails isPersian (default mode) only because of trim/punctuation rules; in complex mode the verdict can flip.
If you need “Arabic but not Persian”, combine the checks:

Edge cases

Pitfalls

  • isArabic is not the negation of isPersian. Use the combined check shown above when you need a clean partition.
  • Arabic-Indic digits (٠-٩) pass; Persian digits (۰-۹) pass too. For digit-level distinction, use arDigitsRegex and faDigitsRegex from the Digits module.

Source

src/modules/isArabic/index.ts · Tests: test/isArabic.spec.ts