text library
Text normalization, Roman Urdu spelling, Urdu digits, slugs, Urdu alphabetical order and bidirectional text.
Same as the pakdatakit/text entry point of the npm package.
Enums
- BidiDirection
- Direction for wrapBidi: auto follows the first strong letter, rtl and ltr force right-to-left or left-to-right.
- SlugScript
- Which letters slugify keeps in a URL slug: any (Latin and Urdu), latin (a-z only) or urdu (Urdu letters only).
Functions
-
compareUrdu(
String a, String b) → int - Compares two strings in Urdu alphabetical order, for List.sort.
-
isRTL(
String text) → bool - Whether text reads right to left: its first letter is from a right-to-left script such as Urdu or Arabic. Digits, punctuation and spaces are skipped, as in the Unicode bidirectional algorithm's paragraph rule.
-
normalizeRomanUrdu(
String text) → String -
Normalizes informal Roman Urdu spellings to common forms (
kia→kya,nhi→nahi). -
normalizeText(
String text) → String - Normalizes general text: trims, collapses whitespace and applies Unicode NFC.
-
romanUrduKey(
String text) → String -
A phonetic key for Roman Urdu, so that different spellings of the same
name or word match:
MubeenandMobeen,Muhammad,MohammadandMuhammed,RehmanandRahman,Chaudhry,ChaudharyandChaudhery. Compare keys, not the text. -
slugify(
String input, {SlugScript script = SlugScript.any}) → String -
Turns text into a URL slug: lower-case words joined by
-. -
toEnglishDigits(
String text) → String - Converts Urdu and Arabic-Indic digits to English digits (0–9).
-
toUrduDigits(
String text) → String - Converts English and Arabic-Indic digits to Urdu digits (۰–۹).
-
wrapBidi(
String text, [BidiDirection direction = BidiDirection.auto]) → String - Wraps text in Unicode directional isolates, so a name or number in one direction does not reorder the sentence around it (for example an English order number inside an Urdu message).