-
Notifications
You must be signed in to change notification settings - Fork 0
hasPashto
β οΈ Version Recommendation: Always install and use the latest version ofrtl-text-tools(npm install rtl-text-tools@latest). While this specific feature was introduced in an earlier version, the latest release includes crucial bug fixes, better edge-case handling, and improved legacy browser compatibility. Avoid pinning your project to an old version just to use this function.
Detects if a given string contains Pashto characters. Pashto is written using the Arabic script but includes several unique letters that are not found in standard Arabic or Persian. This function specifically checks for those unique Pashto characters to accurately identify the language.
hasPashto(text: string): boolean| Name | Type | Description |
|---|---|---|
text |
string |
The text to check for Pashto characters. |
-
boolean: Returnstrueif the text contains at least one Pashto-specific character, otherwisefalse. Returnsfalsefor empty strings,null, orundefined.
import { hasPashto } from 'rtl-text-tools';
hasPashto("Ψ³ΩΨ§Ω
"); // false (Standard Arabic characters only)
hasPashto("ΩΎΪΨͺΩ"); // true (Contains Ϊ - U+069A)
hasPashto("ΩΌΩΩ"); // true (Contains ΩΌ - U+067C)
hasPashto("Hello"); // false (English/LTR)
hasPashto(""); // false (Empty string)Because Pashto shares most of its alphabet with Arabic and Persian, standard RTL detection isn't enough to identify it. Use hasPashto() to apply Pashto-specific UI or logic:
import { hasRTL, hasPashto } from 'rtl-text-tools';
const userInput = "Ψ―Ψ§ ΩΎΪΨͺΩ ΪΨ¨Ω Ψ―Ω";
if (hasPashto(userInput)) {
// Apply Pashto-specific font or locale settings
applyPashtoLocale();
} else if (hasRTL(userInput)) {
// Fallback to general Arabic/Persian RTL styles
applyArabicStyles();
}Pashto uses the Arabic script but adds several unique letters to represent sounds not present in Arabic. This function checks for the following specific Unicode characters:
| Character | Name | Unicode Range |
|---|---|---|
| ΩΌ | Arabic Letter Tteh | \u067C |
| Ϊ | Arabic Letter Hah with Hamza Above | \u0681 |
| Ϊ | Arabic Letter Hah with Three Dots Above | \u0685 |
| Ϊ | Arabic Letter Dal with Ring | \u0689 |
| Ϊ | Arabic Letter Reh with Ring | \u0693 |
| Ϊ | Arabic Letter Reh with Dot Below and Dot Above | \u0696 |
| Ϊ | Arabic Letter Seen with Dot Below and Dot Above | \u069A |
-
IE11 Compatibility: The underlying regular expression intentionally avoids the ES6
u(unicode) flag to ensure full compatibility with legacy browsers like IE11. -
BMP Only: It relies entirely on Basic Multilingual Plane (BMP) code points (
\uXXXX), which work perfectly without theuflag. -
Performance: Like other detection functions in the library, the regex is optimized for fast execution, returning
truethe moment it finds the first matching Pashto character without scanning the entire string. -
Safe Execution: If the input is falsy (e.g.,
null,undefined, or""), it immediately returnsfalsewithout throwing an error.
-
v1.2.0: Added
hasPashto()to detect Pashto characters as part of the minor languages detection update.
π Home β’ π Getting Started β’ π API Reference β’ π Report Issue
Made with β€οΈ by Homayoun Mohammadi
If you find this project useful, please consider β starring the repo to show your support!
- π Home
- π Getting Started
- π§© API Overview
- π οΈ Framework Guides
- π‘ Use Cases
- π₯οΈ Browser Compatibility
- β FAQ & Troubleshooting
Homayoun Mohammadi
π GitHub β’ βοΈ Email
β Love this project? Star it on GitHub to show your support!