Skip to content

hasPashto

Homayoun edited this page Jul 10, 2026 · 1 revision

Introduced in v1.2.0

⚠️ Version Recommendation: Always install and use the latest version of rtl-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.

πŸ“ Syntax

hasPashto(text: string): boolean

Parameters

Name Type Description
text string The text to check for Pashto characters.

Returns

  • boolean : Returns true if the text contains at least one Pashto-specific character, otherwise false. Returns false for empty strings, null, or undefined.

πŸ’‘ Examples

Basic Usage

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)

Differentiating Pashto from Arabic/Persian

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();
}

🌍 Supported Pashto-Specific Characters

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

βš™οΈ Technical Details & Compatibility

  • 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 the u flag.
  • Performance: Like other detection functions in the library, the regex is optimized for fast execution, returning true the 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 returns false without throwing an error.

πŸ“œ Version History

  • v1.2.0: Added hasPashto() to detect Pashto characters as part of the minor languages detection update.

πŸš€ rtl-text-tools

npm downloads

πŸ‘¨β€πŸ’» Created by

Homayoun Mohammadi
πŸ”— GitHub β€’ βœ‰οΈ Email

⭐ Love this project? Star it on GitHub to show your support!

Clone this wiki locally