ي, ك) to their Persian counterparts (ی, ک). These are the foundational checks used by most other Persian Tools modules.
Functions
isPersian(str, isComplex?, trimPattern?)
Returns true when all characters of str (after trimming) are Persian.
Parameters
| Name | Type | Default | Description |
|---|---|---|---|
str | string | — | text to test |
isComplex | boolean | false | true to allow Persian digits + extended punctuation |
trimPattern | RegExp | /["'-+()؟\s.]/g | characters stripped before the script test |
isFarsi(...)
Alias of isPersian — same signature.
hasPersian(str, isComplex?)
Returns true when str contains at least one Persian character.
hasFarsi(...)
Alias of hasPersian.
autoArabicToPersian(value)
Normalize Arabic-script characters to Persian. Specifically:
ي(U+064A, Arabic ya) →ی(U+06CC, Persian ya)ك(U+0643, Arabic kaf) →ک(U+06A9, Persian kaf)
When to use which
isPersian— gate validation: “the user’s name field must be Persian”.hasPersian— content routing: “this comment contains Persian, send it to the fa-IR moderator”.autoArabicToPersian— input sanitisation: run this on any user-supplied Persian string before storing, comparing, or indexing it.
The Persian–Arabic trap
Several letters in the Persian alphabet share their visual form with Arabic but have different code points. Strings typed on Arabic keyboards include the Arabic versions:| Persian | Arabic |
|---|---|
ی (U+06CC) | ي (U+064A) |
ک (U+06A9) | ك (U+0643) |
autoArabicToPersian first.
Pitfalls
isPersian("")returnsfalse— empty string has nothing to match.isPersian("علي")returnsfalse— theيis an Arabic code point. Normalize first if you want to accept either form.isPersianandisArabicare not mutually exclusive — Persian text falls inside the Arabic Unicode block, so a pure Persian string also passesisArabic. See the Arabic Detection page for the distinction.
Source
src/modules/isPersian/index.ts · Tests: test/isPersian.spec.ts