Skip to content

compareUrdu

function compareUrdu(a, b): -1 | 0 | 1;

Defined in: text.ts:371

Compares two strings in Urdu alphabetical order, for Array.sort.

Letters follow the Unicode CLDR collation for Urdu (ur, CLDR 49): ا آ ب بھ پ پھ ت تھ ٹ ٹھ ث ج جھ چ چھ ح خ د دھ ڈ ڈھ ذ ر رھ ڑ ڑھ ز ژ س ش ص ض ط ظ ع غ ف ق ک کھ گ گھ ل لھ م مھ ن نھ ں ںھ و وھ ہ ھ ۃ ء ی یھ ے. A letter joined with ھ is a letter of its own (so بھ comes after every other ب word). أ ؤ ۂ ئ ۓ sort as ا و ہ ی ے and come just after them when words are otherwise equal, and diacritics only break ties, in CLDR’s order.

Outside the Urdu letters: spaces and punctuation come first, then digits digit by digit (Urdu, Arabic-Indic and ASCII digits are equal; 10 comes before 2), then Urdu letters, then other Arabic-script characters (the look-alikes ك ي ى ه ة, which CLDR does not treat as Urdu letters), then everything else by code point, ignoring ASCII case. Strings that are still equal are ordered by code point, so the result is 0 only for identical strings.

Parameter Type
a string
b string

-1 | 0 | 1

-1, 0 or 1. A value that is not a string is treated as ''. Never throws.

['ے', 'بھائی', 'آم', 'باغ', 'اب'].sort(compareUrdu);
// ["اب", "آم", "باغ", "بھائی", "ے"]