Skip to content

Getting started

Install

bash
npm install urdu-text-utils
bash
pnpm add urdu-text-utils
bash
yarn add urdu-text-utils
bash
bun add urdu-text-utils
html
<!-- Exposes global window.UrduTextUtils -->
<script src="https://cdn.jsdelivr.net/npm/urdu-text-utils/dist/index.iife.js"></script>
html
<script type="module">
  import { normalizeUrdu } from "https://cdn.jsdelivr.net/npm/urdu-text-utils/+esm";
</script>

Node 18 or newer. No runtime dependencies.

Use it

ts
import { normalizeUrdu, searchUrdu, sortUrdu, analyzeUrdu } from "urdu-text-utils";

normalizeUrdu("كيا حال ہے");
// "کیا حال ہے"

searchUrdu("محمد", ["مُحَمَّد علی", "احمد", "محمد خان"]);
// ["مُحَمَّد علی", "محمد خان"]

sortUrdu(["گل", "آم", "بادام"]);
// ["آم", "بادام", "گل"]

analyzeUrdu("پاکستان ایک خوبصورت ملک ہے۔").words;
// 5

CommonJS works too:

js
const { normalizeUrdu } = require("urdu-text-utils");

Where each function fits

You are buildingReach for
A search box over Urdu recordssearchUrdu, highlightUrdu
An A-Z index or a sorted dropdownsortUrdu
Storage or deduplication of user inputnormalizeUrdu
A word-count or reading-time widgetanalyzeUrdu
Dates, prices, phone numberstoUrduDigits, parseUrduNumber
URL slugs for Urdu article titlesurduSlug
Filtering out non-Urdu submissionsisUrdu

One rule worth adopting early

Normalize on the way in, not on the way out.

ts
// When a record is created or updated
const stored = normalizeUrdu(userInput);

// Index this alongside it for search and dedupe
const key = foldUrdu(userInput);

Storing raw input and normalizing at query time means every comparison, every unique constraint and every GROUP BY sees a different spelling of the same word. Normalizing at write time makes the problem disappear once.

Everything is pure

Every export is synchronous, side-effect free and returns a new value. Nothing mutates its arguments, nothing reads globals, nothing touches the network. Safe in a request handler, a worker or a build script.

Released under the MIT License.