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
| Name | Type | Default | Description |
|---|---|---|---|
str | string | — | text to test |
trimPattern | RegExp | /["'-+()\s.]/g | characters stripped before the script test |
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:
- A pure Persian string typed on a Persian keyboard also passes
isArabic— the characters all fall in U+0600–U+06FF. - A pure Arabic string fails
isPersian(default mode) only because of trim/punctuation rules; in complex mode the verdict can flip.
Edge cases
| Input | isArabic(...) | Why |
|---|---|---|
"" | false | Nothing to match |
"السلام" | true | All chars in U+0600–U+06FF |
"عليكم 123" | false | Latin digits are not in the Arabic block |
"عليكم ١٢٣" | true | Arabic-Indic digits are in the Arabic block |
"سلام" (Persian) | true | Persian letters live in the same block |
Pitfalls
isArabicis not the negation ofisPersian. Use the combined check shown above when you need a clean partition.- Arabic-Indic digits (
٠-٩) pass; Persian digits (۰-۹) pass too. For digit-level distinction, usearDigitsRegexandfaDigitsRegexfrom the Digits module.
Source
src/modules/isArabic/index.ts · Tests: test/isArabic.spec.ts