urdu-number-words 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Faakhir Habib
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,296 @@
1
+ <div align="center">
2
+
3
+ # urdu-number-words
4
+
5
+ ### اردو نمبر الفاظ
6
+
7
+ Convert numbers to Urdu words with Pakistani currency (PKR) support.
8
+
9
+ Uses the South Asian numbering system — لاکھ، کروڑ، ارب
10
+
11
+ [![npm version](https://img.shields.io/npm/v/urdu-number-words.svg?style=flat-square)](https://www.npmjs.com/package/urdu-number-words)
12
+ [![npm downloads](https://img.shields.io/npm/dm/urdu-number-words.svg?style=flat-square)](https://www.npmjs.com/package/urdu-number-words)
13
+ [![license](https://img.shields.io/npm/l/urdu-number-words.svg?style=flat-square)](https://github.com/faakhir-habib/urdu-number-words/blob/main/LICENSE)
14
+ [![bundle size](https://img.shields.io/bundlephobia/minzip/urdu-number-words?style=flat-square)](https://bundlephobia.com/package/urdu-number-words)
15
+ [![TypeScript](https://img.shields.io/badge/TypeScript-Ready-blue?style=flat-square&logo=typescript)](https://www.typescriptlang.org/)
16
+
17
+ [Installation](#installation) · [Usage](#usage) · [API](#api) · [Currency Mode](#currency-mode) · [Contributing](#contributing)
18
+
19
+ </div>
20
+
21
+ ---
22
+
23
+ ## Why This Package?
24
+
25
+ Pakistan's financial, legal, and business systems require numbers written in Urdu words — from cheque printing to government documents to invoices. Urdu has **unique words for every number from 1 to 100** (unlike English where you can combine "twenty" + "one"), and uses the South Asian numbering system (لاکھ، کروڑ، ارب) instead of millions and billions.
26
+
27
+ No npm package existed that handled this correctly — until now.
28
+
29
+ **Perfect for:**
30
+
31
+ - 🏦 Cheque printing systems
32
+ - 🧾 Invoices and receipts in Urdu
33
+ - 📄 Legal and government documents
34
+ - 🛒 E-commerce platforms serving Pakistani users
35
+ - 💰 Any financial application needing Urdu amount formatting
36
+
37
+ ## Features
38
+
39
+ - ✅ Numbers to Urdu words (0 to کھربوں and beyond)
40
+ - ✅ South Asian numbering system (ہزار، لاکھ، کروڑ، ارب، کھرب)
41
+ - ✅ Pakistani Rupee (PKR) currency mode with "روپے صرف" suffix
42
+ - ✅ Western to Urdu digit conversion (123 → ۱۲۳)
43
+ - ✅ Ordinal numbers (پہلا، دوسرا، تیسرا)
44
+ - ✅ Negative and decimal number support
45
+ - ✅ TypeScript-first with full type definitions
46
+ - ✅ Zero dependencies
47
+ - ✅ Works in Node.js, browsers, Deno, and Bun
48
+
49
+ ## Installation
50
+
51
+ ```bash
52
+ npm install urdu-number-words
53
+ ```
54
+
55
+ ```bash
56
+ yarn add urdu-number-words
57
+ ```
58
+
59
+ ```bash
60
+ pnpm add urdu-number-words
61
+ ```
62
+
63
+ ## Usage
64
+
65
+ ### Basic Conversion
66
+
67
+ ```typescript
68
+ import { toUrduWords } from 'urdu-number-words';
69
+
70
+ toUrduWords(0); // "صفر"
71
+ toUrduWords(25); // "پچیس"
72
+ toUrduWords(100); // "ایک سو"
73
+ toUrduWords(1500); // "ایک ہزار پانچ سو"
74
+ toUrduWords(100000); // "ایک لاکھ"
75
+ toUrduWords(4325718); // "تینتالیس لاکھ پچیس ہزار سات سو اٹھارہ"
76
+ toUrduWords(10000000); // "ایک کروڑ"
77
+ toUrduWords(1000000000); // "ایک ارب"
78
+ toUrduWords(-42); // "منفی بیالیس"
79
+ ```
80
+
81
+ ### Currency Mode (PKR)
82
+
83
+ ```typescript
84
+ import { toUrduWords } from 'urdu-number-words';
85
+
86
+ toUrduWords(5000, { currency: true });
87
+ // "پانچ ہزار روپے صرف"
88
+
89
+ toUrduWords(1500.75, { currency: true });
90
+ // "ایک ہزار پانچ سو روپے اور پچھتر پیسے صرف"
91
+
92
+ toUrduWords(250000, { currency: true });
93
+ // "ڈھائی لاکھ روپے صرف"
94
+ ```
95
+
96
+ ### Urdu Digits
97
+
98
+ ```typescript
99
+ import { toUrduDigits } from 'urdu-number-words';
100
+
101
+ toUrduDigits(12345); // "۱۲۳۴۵"
102
+ toUrduDigits(1500.75); // "۱۵۰۰.۷۵"
103
+ toUrduDigits("03001234567"); // "۰۳۰۰۱۲۳۴۵۶۷"
104
+ ```
105
+
106
+ ### Ordinal Numbers
107
+
108
+ ```typescript
109
+ import { toUrduOrdinal } from 'urdu-number-words';
110
+
111
+ toUrduOrdinal(1); // "پہلا"
112
+ toUrduOrdinal(2); // "دوسرا"
113
+ toUrduOrdinal(3); // "تیسرا"
114
+ toUrduOrdinal(4); // "چوتھا"
115
+ ```
116
+
117
+ ### CommonJS
118
+
119
+ ```javascript
120
+ const { toUrduWords, toUrduDigits, toUrduOrdinal } = require('urdu-number-words');
121
+
122
+ toUrduWords(786); // "سات سو چھیاسی"
123
+ ```
124
+
125
+ ### Browser (CDN)
126
+
127
+ ```html
128
+ <script src="https://cdn.jsdelivr.net/npm/urdu-number-words/dist/index.min.js"></script>
129
+ <script>
130
+ console.log(UrduNumberWords.toUrduWords(786));
131
+ // "سات سو چھیاسی"
132
+ </script>
133
+ ```
134
+
135
+ ## API
136
+
137
+ ### `toUrduWords(num, options?)`
138
+
139
+ Converts a number to Urdu words.
140
+
141
+ | Parameter | Type | Description |
142
+ |-----------|------|-------------|
143
+ | `num` | `number \| string` | The number to convert. Use string for very large numbers. |
144
+ | `options` | `object` | Optional configuration (see below). |
145
+
146
+ **Options:**
147
+
148
+ | Option | Type | Default | Description |
149
+ |--------|------|---------|-------------|
150
+ | `currency` | `boolean` | `false` | Enable PKR currency mode. |
151
+ | `currencyName` | `string` | `"روپے"` | Currency unit name. |
152
+ | `fractionalName` | `string` | `"پیسے"` | Fractional unit name. |
153
+ | `appendOnly` | `boolean` | `false` | Append "صرف" at the end in currency mode. |
154
+
155
+ **Returns:** `string` — The Urdu words representation.
156
+
157
+ ### `toUrduDigits(num)`
158
+
159
+ Converts Western digits (0-9) to Urdu digits (۰-۹).
160
+
161
+ | Parameter | Type | Description |
162
+ |-----------|------|-------------|
163
+ | `num` | `number \| string` | The number to convert. |
164
+
165
+ **Returns:** `string` — The number with Urdu digits.
166
+
167
+ ### `toUrduOrdinal(num)`
168
+
169
+ Converts a number to its Urdu ordinal form.
170
+
171
+ | Parameter | Type | Description |
172
+ |-----------|------|-------------|
173
+ | `num` | `number` | The number to convert (1-100). |
174
+
175
+ **Returns:** `string` — The Urdu ordinal word.
176
+
177
+ ## Numbering System
178
+
179
+ This package uses the **South Asian numbering system** used in Pakistan, India, Bangladesh, and Nepal:
180
+
181
+ <div align="center">
182
+
183
+ | Value | Urdu | Transliteration | Western Equivalent |
184
+ |------:|------|----------------|--------------------|
185
+ | 1 | ایک | ek | one |
186
+ | 10 | دس | das | ten |
187
+ | 100 | سو | sau | hundred |
188
+ | 1,000 | ہزار | hazaar | thousand |
189
+ | 1,00,000 | لاکھ | lakh | hundred thousand |
190
+ | 10,00,000 | دس لاکھ | das lakh | million |
191
+ | 1,00,00,000 | کروڑ | crore | ten million |
192
+ | 1,00,00,00,000 | ارب | arab | billion |
193
+ | 1,00,00,00,00,000 | کھرب | kharab | hundred billion |
194
+
195
+ </div>
196
+
197
+ ## Real-World Examples
198
+
199
+ ### Cheque Printing
200
+
201
+ ```typescript
202
+ const amount = 250750.50;
203
+ const inWords = toUrduWords(amount, { currency: true });
204
+ // "دو لاکھ پچاس ہزار سات سو پچاس روپے اور پچاس پیسے صرف"
205
+
206
+ const inDigits = toUrduDigits(amount);
207
+ // "۲۵۰۷۵۰.۵۰"
208
+ ```
209
+
210
+ ### Invoice Line Item
211
+
212
+ ```typescript
213
+ function formatUrduAmount(amount: number): string {
214
+ return `${toUrduDigits(amount)} (${toUrduWords(amount, { currency: true })})`;
215
+ }
216
+
217
+ formatUrduAmount(15000);
218
+ // "۱۵۰۰۰ (پندرہ ہزار روپے صرف)"
219
+ ```
220
+
221
+ ### Custom Currency
222
+
223
+ ```typescript
224
+ toUrduWords(1500, {
225
+ currency: true,
226
+ currencyName: "ڈالر",
227
+ fractionalName: "سینٹ",
228
+ });
229
+ // "ایک ہزار پانچ سو ڈالر صرف"
230
+ ```
231
+
232
+ ## Edge Cases Handled
233
+
234
+ ```typescript
235
+ toUrduWords(0); // "صفر"
236
+ toUrduWords(-1); // "منفی ایک"
237
+ toUrduWords(0.5, { currency: true }); // "صفر روپے اور پچاس پیسے صرف"
238
+ toUrduWords(1000000); // "دس لاکھ"
239
+ toUrduWords("999999999999"); // Handles large numbers via string input
240
+ ```
241
+
242
+ ## TypeScript Support
243
+
244
+ Full TypeScript definitions are included out of the box:
245
+
246
+ ```typescript
247
+ import { toUrduWords, toUrduDigits, toUrduOrdinal } from 'urdu-number-words';
248
+ import type { UrduNumberOptions } from 'urdu-number-words';
249
+
250
+ const options: UrduNumberOptions = {
251
+ currency: true,
252
+ appendOnly: true,
253
+ };
254
+
255
+ const result: string = toUrduWords(5000, options);
256
+ ```
257
+
258
+ ## Contributing
259
+
260
+ Contributions are welcome! Whether it's fixing an Urdu word, adding features, or improving docs.
261
+
262
+ ```bash
263
+ # Clone the repo
264
+ git clone https://github.com/faakhir-habib/urdu-number-words.git
265
+ cd urdu-number-words
266
+
267
+ # Install dependencies
268
+ npm install
269
+
270
+ # Run tests
271
+ npm test
272
+
273
+ # Build
274
+ npm run build
275
+ ```
276
+
277
+ Please open an issue first to discuss what you'd like to change.
278
+
279
+ ## Related Packages
280
+
281
+ - [`to-words`](https://www.npmjs.com/package/to-words) — Multi-locale number to words (no Urdu support)
282
+ - [`number-to-arabic-words`](https://www.npmjs.com/package/number-to-arabic-words) — Arabic number words (not Urdu)
283
+
284
+ ## License
285
+
286
+ [MIT](LICENSE) © [Faakhir Habib](https://github.com/faakhir-habib)
287
+
288
+ ---
289
+
290
+ <div align="center">
291
+
292
+ Made with ❤️ in Pakistan 🇵🇰
293
+
294
+ If this package helped you, please ⭐ the repo!
295
+
296
+ </div>