-
Notifications
You must be signed in to change notification settings - Fork 0
hasPunjabi
β οΈ 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 Punjabi (Shahmukhi) characters. Punjabi written in the Shahmukhi script uses the Urdu alphabet. This function checks for specific Urdu/Punjabi letters (such as the Noon Ghunna, Yeh Barree, and retroflex consonants) to accurately identify the text as Punjabi or Urdu, distinguishing it from standard Arabic or Persian.
hasPunjabi(text: string): boolean| Name | Type | Description |
|---|---|---|
text |
string |
The text to check for Punjabi/Urdu characters. |
-
boolean: Returnstrueif the text contains at least one Punjabi-specific character, otherwisefalse. Returnsfalsefor empty strings,null, orundefined.
import { hasPunjabi } from 'rtl-text-tools';
hasPunjabi("Ψ³ΩΨ§Ω
"); // false (Standard Arabic characters only)
hasPunjabi("ΩΎΩΨ¬Ψ§Ψ¨Ϋ"); // true (Contains Ϋ - U+06D2)
hasPunjabi("ΩΉΩΩΉ"); // true (Contains ΩΉ - U+0679)
hasPunjabi("Hello"); // false (English/LTR)
hasPunjabi(""); // false (Empty string)Because Punjabi (Shahmukhi) shares most of its alphabet with Arabic and Persian, standard RTL detection isn't enough to identify it. Use hasPunjabi() to apply specific UI or logic:
import { hasRTL, hasPunjabi } from 'rtl-text-tools';
const userInput = "ΨͺΫΨ§ΪΨ§ ΩΨ§ΪΊ Ϊ©Ϋ Ψ§ΫΨ";
if (hasPunjabi(userInput)) {
// Apply Punjabi/Urdu-specific font or locale settings
applyPunjabiLocale();
} else if (hasRTL(userInput)) {
// Fallback to general Arabic/Persian RTL styles
applyArabicStyles();
}Punjabi (Shahmukhi) uses the Urdu script, which adds several unique letters to represent retroflex sounds and nasalization not present in standard Arabic. This function checks for the following specific Unicode characters:
| Character | Name | Unicode Range |
|---|---|---|
| Ϋ | Arabic Letter Yeh Barree | \u06D2 |
| ΪΊ | Arabic Letter Noon Ghunna | \u06BA |
| ΪΎ | Arabic Letter Heh Doachashmee | \u06BE |
| ΩΉ | Arabic Letter Tteh | \u0679 |
| Ϊ | Arabic Letter Ddal | \u0688 |
| Ϊ | Arabic Letter Rreh | \u0691 |
-
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 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
hasPunjabi()to detect Punjabi (Shahmukhi) 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!