Skip to content

hasPunjabi

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 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.

πŸ“ Syntax

hasPunjabi(text: string): boolean

Parameters

Name Type Description
text string The text to check for Punjabi/Urdu characters.

Returns

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

πŸ’‘ Examples

Basic Usage

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)

Differentiating Punjabi/Urdu from Arabic/Persian

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

🌍 Supported Punjabi/Urdu-Specific Characters

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

βš™οΈ 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 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 hasPunjabi() to detect Punjabi (Shahmukhi) 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