arqam 1.1.1 → 2.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/README.md ADDED
@@ -0,0 +1,888 @@
1
+ <!-- README of the Arqam library and its Arabic engine (GitHub and npm): one README for both; ar/README.md
2
+ points here and the English engine keeps en/README.md. Every example below is checked by tests/readme.test.js.
3
+ The cards in images/readme/ are written from the engine by work/imgs (see docs/DEVELOPER.md). -->
4
+ <p align="center">
5
+ <img src="https://arqampro.com/images/ArqamLogo_2_128.png" width="96" height="96" alt="Arqam logo">
6
+ </p>
7
+
8
+ <h1 align="center">Arqam (أرقام) — numbers in words</h1>
9
+
10
+ <p align="center">(c) 2020-2026 Mohsen Alyafei</p>
11
+
12
+ <p align="center">
13
+ Currency amounts, numbers (cardinals and ordinals), dates and times in correct words: Arabic (تفقيط, tafqeet, also written tafqit or tafgeet), with full إعراب and tashkeel, and English.<br>
14
+ Arabic numbers to words in JavaScript: the successor of tafqit and nArabicWords.<br>
15
+ Pure JavaScript · no dependencies · no network · MIT licence
16
+ </p>
17
+
18
+ <p align="center">
19
+ <a href="https://arqampro.com"><b>Try it online</b></a> ·
20
+ <a href="https://arqampro.com/docs/manual.html"><b>Manual</b></a> ·
21
+ <a href="https://arqampro.com/docs/playground.html"><b>Playground</b></a> ·
22
+ <a href="https://arqampro.com/download/"><b>Download</b></a>
23
+ </p>
24
+
25
+ <p align="center">
26
+ <img alt="licence MIT" src="https://img.shields.io/badge/licence-MIT-blue">
27
+ <img alt="no dependencies" src="https://img.shields.io/badge/dependencies-none-brightgreen">
28
+ <img alt="ES module" src="https://img.shields.io/badge/module-ES%20(.mjs)-informational">
29
+ <img alt="TypeScript types" src="https://img.shields.io/badge/types-included-informational">
30
+ </p>
31
+
32
+ <p align="center"><img src="https://arqampro.com/images/readme/banner.png" width="820" alt="Arqam writes 1250.50 Saudi riyals in Arabic words with full tashkeel, coloured by role"></p>
33
+
34
+ ## Arabic numbers in words, written the way a grammarian would
35
+
36
+ Cheques, invoices, contracts and certificates need amounts in words that are *right*, not almost right.
37
+ Arqam writes them with the correct gender, number and case every time, and is checked against
38
+ 285,624 reference entries. The successor of tafqit and nArabicWords.
39
+
40
+ | Why Arqam | What you get |
41
+ |---|---|
42
+ | ✅&nbsp;**Correct&nbsp;Arabic,&nbsp;every&nbsp;time** | Gender agreement for 3–10, the dual, all three cases of إعراب (rafʿ, naṣb and jarr) and tashkeel at six levels, from none to full, checked against all 285,624 entries of the golden book |
43
+ | 💰&nbsp;**Ready&nbsp;for&nbsp;cheques&nbsp;and&nbsp;invoices** | 188 currencies with their subunits, «فقط … لا غير», the legal wording, and the same amount in English |
44
+ | ♾️&nbsp;**No&nbsp;size&nbsp;limit** | Whole numbers of any length and decimals with as many places as you need; the benchmark writes numbers of up to 1,000,000 digits |
45
+ | 📅&nbsp;**More&nbsp;than&nbsp;amounts** | Ordinals up to 999,999, Hijri and Gregorian dates, times and fractions |
46
+ | 🔁&nbsp;**Words&nbsp;back&nbsp;to&nbsp;numbers** | `arqam/words` reads Arabic amounts back into figures, to check a document, including local dialects: «ألفين وخمسمية» as 2500 |
47
+ | 🎓&nbsp;**Explains&nbsp;its&nbsp;own&nbsp;grammar** | `arqam/explain` gives each word's case (الإعراب), the reason and the rule: for schools, students and proofreaders |
48
+ | 📏&nbsp;**Units&nbsp;of&nbsp;measure** | `arqam/units`: 304 units, by their international or Arabic names |
49
+ | 🌐&nbsp;**Arabic&nbsp;and&nbsp;English** | `arqam/en` writes the same amount in UK or US English, for bilingual documents |
50
+ | 📖&nbsp;**The&nbsp;golden&nbsp;book** | A free reference of Arabic number words: 7,934 numbers in every gender and case, with no marks, the tanween alif or full tashkeel, with and without the legal form, as JSON (285,624 entries). Use it to test any tafqeet engine, in any programming language: [golden/](https://github.com/MohsenAlyafei/arqam/blob/master/golden/) · [see it online](https://arqampro.com/docs/golden.html) |
51
+ | 🪶&nbsp;**Light&nbsp;and&nbsp;private** | Pure JavaScript, no dependencies, nothing sent over the network, TypeScript types, MIT licence |
52
+
53
+ **Try it in ten seconds:**
54
+
55
+ ```js
56
+ import arqam from "arqam";
57
+ arqam("1250.50", "EGP");
58
+ // ألف ومائتان وخمسون جنيهًا مصريًا، وخمسون قرشًا
59
+ ```
60
+
61
+ <p align="left"><img src="https://arqampro.com/images/readme/example-egp.png" width="690" alt="arqam(&quot;1250.50&quot;, &quot;EGP&quot;) in coloured Arabic words"></p>
62
+
63
+ Or use it online, free and with nothing to install, at **[arqampro.com](https://arqampro.com)**.
64
+
65
+ ### One library, one engine per language
66
+
67
+ ```js
68
+ import arqam from "arqam";
69
+ import "arqam/en";
70
+
71
+ arqam("1250.50", "ar-QA", {style: "currency", currency: "QAR"}); // ألف ومائتان وخمسون ريالًا قطريًا، وخمسون درهمًا
72
+ arqam("1250.50", "en-US", {style: "currency", currency: "QAR"}); // One Thousand Two Hundred Fifty Qatari Riyals and Fifty Dirhams
73
+ arqam(1250); // ألف ومائتان وخمسون
74
+ // a BigInt, for whole numbers beyond a JavaScript number's exact range:
75
+ arqam(9007199254740993n, "SAR"); // تسعة كوادرليونات وسبعة تريليونات ومائة وتسعة وتسعون مليارًا ومائتان وأربعة وخمسون مليونًا وسبعمائة وأربعون ألفًا وتسعمائة وثلاثة وتسعون ريالًا سعوديًا
76
+ ```
77
+
78
+ <p align="left"><img src="https://arqampro.com/images/readme/example-big.png" width="690" alt="Arqam: arqam(9007199254740993n, &quot;SAR&quot;), in coloured words"></p>
79
+
80
+ `arqam` is shaped as JavaScript's `Intl`: `arqam.toWords(n, locales, options)` is `n.toLocaleString(locales, options)`
81
+ in words, and `new arqam.NumberFormat(locales, options)` is `Intl.NumberFormat`. `arqam(n, locales, options)` is the
82
+ same as `arqam.toWords`, and a currency code in place of the locale makes the number an amount (`arqam(n, "QAR")`, the same as `arqam(n, {currency: "QAR"})`):
83
+
84
+ ```js
85
+ arqam("1250.50", "DZD"); // ألف ومائتان وخمسون دينارًا جزائريًا، وخمسون سنتيمًا
86
+ arqam("2", "DZD"); // ديناران جزائريان
87
+ arqam("2", "DZD", {prefix: "فقط", suffix: "لا غير"}); // فقط ديناران جزائريان اثنان لا غير
88
+ ```
89
+
90
+ <p align="left"><img src="https://arqampro.com/images/readme/example-dzd.png" width="690" alt="arqam(&quot;2&quot;, &quot;DZD&quot;) in coloured Arabic words"></p>
91
+
92
+ «واحد/اثنان» after the noun is written only in the legal form and the cheque form («فقط … لا غير»), where the number
93
+ is said twice; `emphasisOneTwo: "on"` writes it always.
94
+
95
+ The locale chooses the language, and
96
+ Intl's option names, defaults and methods are kept; Arqam's own options sit beside them.
97
+
98
+ > **Arqam 2 is my latest new library.** Version 1.1.2 of the npm package `arqam` was my earlier 2020 library; if you use it, stay on
99
+ > `arqam@1`. Version 2 is the Arqam library (`arqam`; its Arabic engine is `arqamAR`, engine version in `package.json` →
100
+ > `arqamEngine`).
101
+
102
+ <p align="center">
103
+ <a href="https://arqampro.com"><img src="https://arqampro.com/images/page-preview.png" width="820" alt="The Arqam page at arqampro.com: a number typed in, its words, and the options"></a><br>
104
+ <sub>The Arqam page at <a href="https://arqampro.com">arqampro.com</a> uses this library. Everything it does, your code can do.</sub>
105
+ </p>
106
+
107
+ ## Web API: tafqeet from any program
108
+
109
+ Arqam also answers over the web at **`https://api.arqampro.com`**, free and with no key, for programs that do not run
110
+ JavaScript: Excel, Python, PHP, C# and no-code tools. (In JavaScript, use the library itself: it needs no internet.)
111
+
112
+ ```text
113
+ https://api.arqampro.com/v1/words?n=1250.50&currency=SAR
114
+ ```
115
+
116
+ ```json
117
+ { "input": "1250.50", "words": "ألف ومائتان وخمسون ريالًا سعوديًا، وخمسون هللةً", "version": "1.90" }
118
+ ```
119
+
120
+ | Call | Gives |
121
+ |---|---|
122
+ | `/v1/words?n=…` | a number or amount in Arabic words |
123
+ | `/v1/bilingual?n=…&currency=…` | Arabic and English at once, in the cheque form |
124
+ | `/v1/english?n=…` | a number or amount in English words |
125
+ | `/v1/date?d=23/11/2026` | a date in words (`calendar=g`, `h` or `b`) |
126
+ | `/v1/time?t=15:45` | a time in words |
127
+ | `/v1/value?text=…` | Arabic words back to their number |
128
+ | `/v1/explain?n=…` | the إعراب of each word |
129
+
130
+ The options are the library's own (`currency`, `tashkeel`, `ierab`, `legal`, `wordOrder` …); `format=text` gives the
131
+ words alone. Excel for Windows, with the amount in A2:
132
+
133
+ ```text
134
+ =WEBSERVICE("https://api.arqampro.com/v1/words?n="&A2&"&currency=SAR&format=text")
135
+ ```
136
+
137
+ ```python
138
+ import requests
139
+ r = requests.get("https://api.arqampro.com/v1/words", params={"n": "1250.50", "currency": "SAR"})
140
+ print(r.json()["words"])
141
+ ```
142
+
143
+ Every call, its options and examples for PHP, C# and curl: [the API page](https://arqampro.com/en/tafqeet/api/).
144
+
145
+ ## Contents
146
+
147
+ | **🚀 Get started** | **📚 The Arabic engine** | **🌐 Languages and more** |
148
+ |:---|:---|:---|
149
+ | [Why Arqam](#why-arqam)<br>[Why not ask an AI model?](#why-not-ask-an-ai-model-to-do-the-job)<br>[Features at a glance](#features-at-a-glance)<br>[Install](#install)<br>[Quick start](#quick-start)<br>[Web API](#web-api-tafqeet-from-any-program) | [The engine (arqamAR)](#the-arabic-engine-arqamar)<br>[Specifications](#specifications)<br>[The calls](#the-calls)<br>[Options](#options)<br>[The Intl-style formatter](#the-intl-style-formatter)<br>[Units of measure](#units-of-measure)<br>[Regions and time zones](#regions-and-time-zones)<br>[Approximate quantities](#approximate-quantities)<br>[Words back to numbers](#words-back-to-numbers)<br>[Explain the grammar](#explain-the-grammar)<br>[Eastern and Western digits](#arabic-eastern-and-arabic-western-numbers) | [Languages](#languages)<br>[Two languages at once](#two-languages-at-once)<br>[Documents: cheques, invoices …](#documents-cheques-invoices-receipts-contracts)<br>[Adding a language](#adding-a-language)<br>[TypeScript, browsers and size](#typescript-browsers-node-and-size)<br>[Documentation and online tools](#documentation-and-online-tools)<br>[This repository](#this-repository)<br>[Licence and author](#licence-and-author) |
150
+
151
+ <!-- gen:why -->
152
+ ## Why Arqam
153
+
154
+ Many websites and libraries turn numbers into Arabic words, and many get the grammar wrong: the gender of the number against the counted noun for three to ten, the dual, the case endings, the scale words, large numbers, fractions.
155
+
156
+ Arqam was written so that a number or an amount — on a cheque, an invoice, a contract — comes out in correct Arabic every time, with the options a real document needs, and free for everyone.
157
+
158
+ **Arqam** (أرقام) means "numbers"; the Arabic engine is `arqamAR`, the English one `arqamEN`.
159
+
160
+ | What you need | Arqam |
161
+ |---|---|
162
+ | Numbers and amounts in words (تفقيط) | 188 currencies, 304 units of measure, ordinals, percentages, Gregorian and Hijri dates, times and fractions |
163
+ | No limit on the size of the number | any number of whole and decimal digits: only the computer's memory sets the limit. Words back to numbers reads whole numbers of up to thirty-six (36) digits |
164
+ | إعراب: الرفع والنصب والجر | option `ierab` |
165
+ | Tashkeel (التشكيل) | six (6) modes, from none to full: option `tashkeel` |
166
+ | «اشرح»: the grammar of every word | every word with its إعراب, the reason and the rule: `arqam/explain` |
167
+ | Words back to numbers | `arqam/words`: dialect words too, and `verify()` checks words against their figure |
168
+ | Legal form for cheques and contracts | option `legal` |
169
+ | The words in parts, for separate fields | `formatToParts()`: the number, the decimals, the currency and the sub-unit, each labelled |
170
+ | Ranges in words («من … إلى …») | `formatRange()` for numbers, currencies, counted nouns, units, percentages, ordinals, fractions, times, Gregorian and Hijri dates |
171
+ | Tests | eighty-one (81) engine Test Cases; seven hundred and sixty-six (766) words-to-numbers cases; 53,859 «اشرح» calls (250,564 words) checked word by word, with no mismatch; more than 160,000 random checks in eleven (11) parts; thirty-eight (38) page-test files in a real browser |
172
+
173
+ The figures are written by `tools/build_why.js` from the library and from the latest passing test run.
174
+
175
+ ### What makes Arqam different from other libraries
176
+
177
+ - **A rule-based Arabic grammar engine.** Arqam works from the rules of Arabic grammar rather than fixed templates. It handles duals, iḍāfa, the three cases (nominative, accusative, genitive) and gender agreement. It can explain every word's grammar (إعراب الكلمات), and it offers 6 levels of tashkeel: none, alif, fatha, tanween, endings and full.
178
+ - **Numbers of any length, and wide coverage.** There is no upper limit on the number of digits. Arqam covers 188 currencies, 304 units of measure, Hijri and Gregorian dates, times, fractions and ordinals. It has a legal mode for cheques that leaves no room for ambiguity, and it reads written Arabic, colloquial phrasing included, back into digits.
179
+ - **Arabic and English from one call.** With the English add-on, `toBilingual()` gives matching Arabic and English words for the same amount, for bilingual invoices, contracts and financial documents.
180
+ - **One design, a familiar API.** Units of measure use the same `registerCurrency()` machinery as currencies (`secondAs`: iḍāfa or qualifier), and `arqamAR.NumberFormat` follows `Intl.NumberFormat` (`style: "currency"`, `style: "unit"`). The library stays compact and familiar to JavaScript and TypeScript developers.
181
+ - **Private and open.** Everything runs on the user's device, with no dependencies, so nothing typed leaves it. The engine is checked against the Golden Book's 285,624 reference entries. Arqam is Open Source under the MIT licence.
182
+ <!-- /gen:why -->
183
+
184
+ ## Why not ask an AI model to do the job?
185
+
186
+ AI models are useful for many things, but writing an amount in words for a cheque or a contract is not one of them.
187
+ Asking a large language model to write out "432,215.750 KWD in the accusative, with full tashkeel" runs into these limits:
188
+
189
+ - **Not always right.** It can get subtle gender, case or tanween rules wrong, and the error looks just as fluent as
190
+ a correct answer. That is not acceptable on a bank cheque or in a legal contract.
191
+ - **Not always the same.** There is no guarantee that a model gives the same words time and time again: the answer can
192
+ change from one request to the next, and depends on the model, its version and settings, its strength, its training
193
+ and its capabilities. A new version of the same model can write the same amount differently.
194
+ - **Hard to check.** A model does not show the rule behind each word, so every answer has to be checked by someone who
195
+ knows the grammar.
196
+ - **Slow and online.** Each answer needs a network call and takes seconds; it cannot run offline, inside a form or in
197
+ a batch of thousands of amounts without waiting.
198
+ - **Your data leaves your system.** The amount, and often the payee or the contract around it, is sent to a third
199
+ party, which banks, auditors and legal teams may not allow.
200
+ - **It costs and it can stop.** Requests are paid for or limited, need an account and a key, and depend on a service
201
+ that can change or stop.
202
+
203
+ Arqam is built for exactly this job:
204
+
205
+ - It runs locally and offline, in tens of microseconds, on deterministic classical grammar rules: the same input gives
206
+ the same words every time, on every machine.
207
+ - Every result is checked against the 285,624 entries of the golden book.
208
+ - It explains its own grammar, word by word, with `arqam/explain`.
209
+ - Nothing is sent anywhere, and it costs nothing.
210
+
211
+ ```js
212
+ arqam.toWords("432215.750", "KWD", {ierab: "nasb", tashkeel: "full"});
213
+ // أَرْبَعَمِائَةٍ وَاثْنَيْنِ وَثَلَاثِينَ أَلْفًا وَمِائَتَيْنِ وَخَمْسَةَ عَشَرَ دِينَارًا كُوَيْتِيًّا، وَسَبْعَمِائَةٍ وَخَمْسِينَ فِلْسًا
214
+ ```
215
+
216
+ <p align="left"><img src="https://arqampro.com/images/readme/example-kwd.png" width="690" alt="Arqam: 432215.750 Kuwaiti dinars with full tashkeel, in coloured words"></p>
217
+
218
+ ## Features at a glance
219
+
220
+ Everything below is in the library today, with no dependencies and no network.
221
+
222
+ **1. Arabic grammar engine**
223
+
224
+ - **Gender agreement (المذكر والمؤنث):** 1 and 2 agree with the counted noun (واحد / واحدة، اثنان / اثنتان); 3–10 take
225
+ the opposite gender; 11 and 12 agree in both parts (أحد عشر، إحدى عشرة); in 13–19 the first part takes the opposite
226
+ gender and عشر / عشرة agrees; the tens do not change and their units follow the rules of 1–9.
227
+ - **Case (الإعراب):** nominative, accusative and genitive (`ierab`) for cardinals, ordinals, duals and sound plurals
228
+ (مائتان / مائتين، ألفان / ألفين، عشرون / عشرين), and for amounts, dates, times and fractions.
229
+ - **Iḍāfa and the dual:** the ن of the dual drops before what it is added to (مائتا ألف، ألفا ريال).
230
+ - **Every form of the counted noun:** singular (1), dual (2), plural (3–10), accusative singular (11–99: ريالًا، دينارًا،
231
+ هللةً) and genitive singular (100 and up), for every currency, unit and noun of your own.
232
+ - **Tashkeel:** six modes, from none, through tanween only (ريالًا), to full tashkeel (`tashkeel`), always in Unicode's
233
+ standard order.
234
+ - **Word order:** largest part first (the default) or smallest first: خمسون ومائتان وألف (`wordOrder`).
235
+ - **Cheques and contracts:** the legal form (`legal`), «فقط … لا غير» (`prefix`, `suffix`) and the figure in brackets.
236
+
237
+ **2. Regional forms**
238
+
239
+ - مائة or مئة (`miah`), written together or apart: ثلاثمائة / ثلاث مائة (`miahSplit`).
240
+ - The Arabic scale (مليار), the short scale (بليون) and the long, European scale (`scale`).
241
+ - The twenty-two (22) Arab League locales, each with its currency, month names (يناير، كانون الثاني، جانفي …), time
242
+ zone and numerals (`locale`).
243
+ - The fraction in words (وخمسون هللة), in figures, as a fraction (و5/10 ريال), with «فاصلة», or digit by digit
244
+ (`decFormat`).
245
+ - Arabic-Eastern (٠١٢٣٤٥٦٧٨٩) and Arabic-Western (0123456789) numbers, in and out.
246
+
247
+ **3. Money and precision**
248
+
249
+ - **Exact input:** text, JavaScript numbers and BigInt, with no floating-point error (19.99 stays 19.99), and no limit
250
+ on the size of a number or on its decimals: decillion (10³³) and far beyond.
251
+ - **188 currencies** (ISO 4217, the withdrawn ones still found in old documents, and 13 cryptocurrencies), each with
252
+ the gender of its unit and sub-unit, every noun form and its number of decimals: two for QAR (ريال / درهم), SAR
253
+ (ريال / هللة), AED (درهم / فلس), EGP (جنيه / قرش), USD and EUR; three for KWD, BHD, OMR, JOD and TND; none for JPY and
254
+ KRW.
255
+ - **Your own currency or noun:** `registerCurrency` with its names, gender and decimals; and 304 units of measure
256
+ ready to use (`arqam/units`).
257
+ - **No silent rounding:** digits beyond the currency's places are cut by default; `rounding: "on"` rounds and carries
258
+ into the whole number (9.999 → 10.00).
259
+ - A sub-unit of zero is left out (مائة ريال), and the figure in brackets can still show it (100.00 QAR).
260
+ - Negative numbers («سالب …»), and `strict` to report input that is not a number instead of returning a default.
261
+
262
+ **4. Beyond money**
263
+
264
+ - Cardinal numbers, masculine or feminine; ordinals from 1 to 999,999 (الأول / الأولى، الحادي عشر / الحادية عشرة).
265
+ - Percentages (بالمائة / بالمئة, decimals included: ثلاثة فاصلة خمسة بالمائة) and approximate quantities (قرابة، بضعة،
266
+ نيّف).
267
+ - Fractions by name (نصف، ثلث، ثلاثة وثلاثة أرباع), as parts, or mixed (`toFraction`).
268
+ - Gregorian and Hijri (Umm al-Qura) dates, times, durations and time zones (`toDate`, `toTime`, `toDateTime`); a Hijri
269
+ date is recognised by «هـ» or by its month name.
270
+ - **Words back to numbers** (`arqam/words`): any tashkeel, missing hamzas (احد / أحد), dialect words (تلاتة، خمستاشر،
271
+ ميتين), amounts, dates, times and durations; `verify()` checks words against their figure, for cheques, invoices and
272
+ OCR.
273
+ - **«اشرح»** (`arqam/explain`): the إعراب of every word, with its reason and rule.
274
+ - An `Intl`-style formatter (`NumberFormat`: `format`, `formatToParts`, `formatRange`).
275
+ - **Bilingual amounts and documents:** the amount in Arabic and English in one call (`toBilingual`), and the wording
276
+ of a cheque, invoice, receipt or contract clause in Arabic, English or both (`toClause`).
277
+
278
+ **5. For developers**
279
+
280
+ - No dependencies and no network; ES modules and plain scripts; the units, the reader, «اشرح» and English are
281
+ separate modules, loaded only if you import them.
282
+ - **One library, many languages:** each language is its own engine (`arqamAR`, `arqamEN` …) reached through `arqam`;
283
+ a new language is a new module.
284
+ - TypeScript declarations for every method, option and value.
285
+ - A misspelt option or value is an error that suggests the right one ("did you mean").
286
+ - A web playground and a full manual, with questions and answers, at [arqampro.com](https://arqampro.com).
287
+ - Tests: the engine's Test Cases, a sweep of 49,424 calls checked word for word, golden sets, round trips through the
288
+ reader, and random tests.
289
+
290
+ ## Install
291
+
292
+ ```
293
+ npm install arqam
294
+ ```
295
+
296
+ ES module only (`.mjs`), for browsers, Node 14.13+, Deno and bundlers.
297
+
298
+ From CommonJS use
299
+ `const {default: arqam} = await import("arqam");`.
300
+
301
+ TypeScript declarations are included.
302
+
303
+ The modules are minified, each under a banner with its version and licence; the readable source is in `src/` on GitHub.
304
+
305
+ `dist/SRI.txt` has an integrity hash for every module.
306
+
307
+ **Without npm**, take the files from [`dist/`](https://github.com/MohsenAlyafei/arqam/blob/master/dist/) in this repository or from the [download page](https://arqampro.com/download/),
308
+ or load the plain scripts in [`src/`](https://github.com/MohsenAlyafei/arqam/blob/master/src/) with a `<script>` tag:
309
+
310
+ ```html
311
+ <script src="https://github.com/MohsenAlyafei/arqam/blob/master/arqamAR.js"></script> <!-- the library: window.arqam, and its Arabic engine window.arqamAR -->
312
+ <script src="https://github.com/MohsenAlyafei/arqam/blob/master/arqamEN.js"></script> <!-- optional: English, by its locale ("en-GB") -->
313
+ <script src="https://github.com/MohsenAlyafei/arqam/blob/master/arqamWordsToNumbers.js"></script> <!-- optional: words back to numbers -->
314
+ <script src="https://github.com/MohsenAlyafei/arqam/blob/master/arqamExplain.js"></script> <!-- optional: «اشرح» -->
315
+ <script src="https://github.com/MohsenAlyafei/arqam/blob/master/arqamUnits.js"></script> <!-- optional: NumberFormat style "unit" -->
316
+ ```
317
+
318
+ ## Quick start
319
+
320
+ ```js
321
+ import arqam from "arqam";
322
+ import "arqam/en";
323
+
324
+ arqam("1250.50", "ar-SA", {style: "currency", tashkeel: "full", prefix: "فقط", suffix: "لا غير", brackets: "end", numberingSystem: "latn"});
325
+ // فَقَطْ أَلْفٌ وَمِائَتَانِ وَخَمْسُونَ رِيَالًا سُعُودِيًّا، وَخَمْسُونَ هَلَلَةً لَا غَيْرْ (1,250.50 SAR)
326
+ arqam.toDate("18/11/2026", {calendar: "both", style: "compact"});
327
+ // 18 نوفمبر 2026م، الموافق 8 جمادى الآخرة 1448هـ
328
+ arqam.toDate("18/11/2026", {calendar: "both", tashkeel: "full"});
329
+ // الثَّامِنَ عَشَرَ مِنْ شَهْرِ نُوفَمْبِرَ لِعَامِ أَلْفَيْنِ وَسِتَّةٍ وَعِشْرِينَ لِلْمِيلَادِ، الْمُوَافِقُ الثَّامِنَ مِنْ شَهْرِ جُمَادَى الْآخِرَةِ لِعَامِ أَلْفٍ وَأَرْبَعِمِائَةٍ وَثَمَانِيَةٍ وَأَرْبَعِينَ لِلْهِجْرَةِ
330
+ arqam("1250.50", "en-GB", {style: "currency", currency: "QAR", only: "end", brackets: "end"});
331
+ // One Thousand Two Hundred and Fifty Qatari Riyals and Fifty Dirhams Only (QAR 1,250.50)
332
+ arqam("1.23456"); // واحد، ومائتان وخمسة وثلاثون جزءًا من الألف
333
+ arqam("1.005", "ar-QA", {style: "currency"}); // ريال قطري، ودرهم
334
+ arqam("1.005", "ar-QA", {style: "currency", roundingMode: "trunc"}); // ريال قطري
335
+ arqam("5", {signDisplay: "always"}); // موجب خمسة
336
+ ```
337
+
338
+ <p align="left"><img src="https://arqampro.com/images/readme/example-date.png" width="690" alt="Arqam: 18/11/2026 in words with its Hijri date, in full tashkeel and in the compact form"></p>
339
+
340
+ As JavaScript's `Intl.NumberFormat`, one `arqam.NumberFormat` writes every language: the locale chooses it.
341
+ `toWords` gives the words of its `format`; `formatToParts`, `formatRange`, `formatRangeToParts` and `resolvedOptions`
342
+ are there too.
343
+
344
+ ```js
345
+ new arqam.NumberFormat("ar-QA", {style: "currency", currency: "QAR"}).format(1250.5); // ألف ومائتان وخمسون ريالًا قطريًا، وخمسون درهمًا
346
+ new arqam.NumberFormat("en-GB", {style: "currency", currency: "QAR"}).format(1250.5); // One Thousand Two Hundred and Fifty Qatari Riyals and Fifty Dirhams
347
+ ```
348
+
349
+ Pass amounts as text (`"1250.50"`): a JS number keeps only about 16 significant digits.
350
+
351
+ The rounding is Intl's: 3
352
+ places for a number, the currency's minor unit for an amount and a whole number for a percentage, half up;
353
+ `maximumFractionDigits` and `roundingMode: "trunc"` change it.
354
+
355
+ Each language has its own options beside Intl's: see
356
+ [Arabic](#the-arabic-engine-arqamar) and [English](https://github.com/MohsenAlyafei/arqam/blob/master/en/README.md).
357
+
358
+ ### More Arabic examples
359
+
360
+ ```js
361
+ import arqam from "arqam";
362
+
363
+ arqam("1250.50", "MAD"); // ألف ومائتان وخمسون درهمًا مغربيًا، وخمسون سنتيمًا
364
+ ```
365
+
366
+ <p align="left"><img src="https://arqampro.com/images/readme/example-mad.png" width="690" alt="arqam(&quot;1250.50&quot;, &quot;MAD&quot;) in coloured Arabic words"></p>
367
+
368
+ ```js
369
+ arqam("250750.25", "IQD");
370
+ // مائتان وخمسون ألفًا وسبعمائة وخمسون دينارًا عراقيًا، ومائتان وخمسون فلسًا
371
+ ```
372
+
373
+ <p align="left"><img src="https://arqampro.com/images/readme/example-iqd.png" width="690" alt="arqam(&quot;250750.25&quot;, &quot;IQD&quot;) in coloured Arabic words"></p>
374
+
375
+ ```js
376
+ arqam("3", "LBP"); // ثلاث ليرات لبنانية
377
+ ```
378
+
379
+ <p align="left"><img src="https://arqampro.com/images/readme/example-lbp.png" width="690" alt="arqam(&quot;3&quot;, &quot;LBP&quot;) in coloured Arabic words"></p>
380
+
381
+ ```js
382
+ arqam("11", "SDG"); // أحد عشر جنيهًا سودانيًا
383
+ ```
384
+
385
+ <p align="left"><img src="https://arqampro.com/images/readme/example-sdg.png" width="690" alt="arqam(&quot;11&quot;, &quot;SDG&quot;) in coloured Arabic words"></p>
386
+
387
+ And more:
388
+
389
+ ```js
390
+ arqam("1250.50", "DZD", {prefix: "فقط", suffix: "لا غير"});
391
+ // فقط ألف ومائتان وخمسون دينارًا جزائريًا، وخمسون سنتيمًا لا غير
392
+ arqam.toWords("2000000", "DZD", {ierab: "jarr"}); // مليوني دينار جزائري
393
+ arqam.toWords("2500", "LBP", {approx: "about"}); // قرابة ألفين وخمسمائة ليرة لبنانية
394
+ arqam.toWords("1500", "ar-IQ", {style: "currency"}); // ألف وخمسمائة دينار عراقي
395
+ arqam.toWords("101000", {legal: "full"}); // مائة ألف وألف
396
+ arqam.toWords("21", {style: "ordinal", ordinal: "feminine"}); // الحادية والعشرون
397
+ arqam.toWords("25%"); // خمسة وعشرون بالمائة
398
+
399
+ "في " + arqam.toDate("26/11/2026", {ierab: "jarr"});
400
+ // في السادس والعشرين من شهر نوفمبر لعام ألفين وستة وعشرين للميلاد
401
+ arqam.toTime("15:45"); // الساعة الثالثة وخمس وأربعون دقيقةً عصرًا
402
+ arqam.toTime("15:45", {timeParts: "on"}); // الساعة الرابعة إلا الربع عصرًا
403
+ arqam.toFraction("3 1/2"); // ثلاثة ونصف
404
+ arqam.toFraction("3/4"); // ثلاثة أرباع
405
+ ```
406
+
407
+ <p align="left"><img src="https://arqampro.com/images/readme/example-time.png" width="690" alt="Arqam: the time 15:45 as a quarter to four, in coloured words"></p>
408
+
409
+ Arabic-Western and Arabic-Eastern numbers are both accepted, with `-` before and `%` after.
410
+
411
+ ## The Arabic engine (arqamAR)
412
+
413
+ Arabic is the default language. The default export (`arqam`) and the named export (`arqamAR`) give the same calls and
414
+ the same Arabic words:
415
+
416
+ ```js
417
+ import arqam from "arqam";
418
+ // or
419
+ import {arqamAR} from "arqam";
420
+ ```
421
+
422
+ ### Classical-grade grammar engine
423
+
424
+ `arqamAR` is a deep, authoritative Arabic morphological and syntactic engine (Naḥw & Ṣarf) built for cardinals,
425
+ ordinals and tafqeet:
426
+
427
+ - **Strict Basran Iḍāfa ordinals (1–999,999):** follows classical Basran syntax (for example مائة الألف، مائتا الألف،
428
+ بعد مائتي الألف), the compound fatḥa (الْحَادِيَ عَشَرَ), and full gender and case agreement.
429
+ - **Full three-case inflection (iʿrāb):** nominative (rafʿ), accusative (naṣb) and genitive (jarr) across cardinals,
430
+ ordinals (الْأَوَّلُ / الْأَوَّلَ / الْأَوَّلِ), duals (مائتا / مائتي) and sound plurals (ـُونَ / ـِينَ).
431
+ - **Counted noun customisation:** four forms of the counted noun, case switching, ascending and descending word order,
432
+ and strict Classical/MSA grammar rules.
433
+
434
+ ### What's new: from `arqam@1` to Arqam 2
435
+
436
+ Arqam 2 goes far beyond the original tafqit library (`arqam@1`), introducing:
437
+
438
+ - Full three-case iʿrāb and Basran Iḍāfa ordinals up to 999,999.
439
+ - Six tashkeel modes, written in Unicode's standard order.
440
+ - **Reverse parsing (`arqam/words`):** dialect-tolerant conversion from Arabic words back to numbers.
441
+ - **Grammar breakdown (`arqam/explain`):** a word-by-word morphological and syntactic explainer.
442
+
443
+ As far as we know, no other open-source library with no dependencies brings together this depth of Arabic grammar.
444
+
445
+ ```js
446
+ import arqam from "arqam";
447
+
448
+ arqam.toWords("1250.50", "QAR"); // ألف ومائتان وخمسون ريالًا قطريًا، وخمسون درهمًا
449
+ ```
450
+
451
+
452
+ ### What it does
453
+
454
+ Write numbers, amounts and dates in correct Arabic: the gender agreement of 3–10, the dual, the case endings
455
+ (الرفع، النصب، الجر), full or partial tashkeel, large numbers and fractions. 188 currencies with their sub-units,
456
+ 304 units of measure, ordinals, percentages, negative numbers, approximate quantities (قرابة، بضعة…), Gregorian or
457
+ Hijri (Umm al-Qura) dates, the time with its time zone, and typed fractions. It also reads Arabic number words back
458
+ into numbers, checks words against their figure, and explains the grammar of every word.
459
+
460
+ ## Specifications
461
+
462
+ <details>
463
+ <summary>Show the specifications</summary>
464
+
465
+ | Feature | Arqam |
466
+ |---|---|
467
+ | Whole digits | No limit (text or BigInt; only memory sets the limit); words back to numbers reads up to 36 digits |
468
+ | Decimal places | No limit (thousands and more); a currency's sub-unit by itself; no silent rounding by default |
469
+ | Input digits | Arabic-Western (0–9), Arabic-Eastern (٠–٩) and Persian (۰–۹); the decimal mark `.` or `٫`. Thousands separators are not read by the engine: pass `"1250.5"` (the Arqam page converts what the user types) |
470
+ | Scales | Arabic (مليار), short (بليون) and long (European), with `scale` |
471
+ | Output numerals | Arabic-Western or Arabic-Eastern, with `arabicNumbers` |
472
+ | Currencies | 188 built in, plus your own with `registerCurrency` |
473
+ | Units of measure | 304 built in (`arqam/units`) |
474
+ | Ordinals | 1 to 999,999: Basran Iḍāfa, gender, the three cases, the dual losing its ن |
475
+ | Approximate quantities | Seven forms with `approx`: about (قرابة), over (ما يزيد على), under (أقل من), at least (ما لا يقل عن), at most (ما لا يزيد على), few (بضعة: 3 to 9, also of tens, hundreds and thousands) and plus (نيّف: 1 to 9 above a ten or a hundred); with the right gender and case |
476
+ | Dates and times | Gregorian and Hijri (Umm al-Qura) dates, times, time zones, styles, durations and ranges |
477
+ | Grammar | Gender polarity of 3–10, the three cases, the dual losing its ن, the four forms of the counted noun, six tashkeel modes, word order |
478
+ | Words back to numbers, `verify()` | Reads Fuṣḥā (الفصحى) and colloquial Arabic text back into digits. Dialect and hamza tolerant (`arqam/words`); `verify()` reports what differs |
479
+ | Grammar explainer | An interactive word-by-word إعراب breakdown with the rule for each word (`arqam/explain`), and a code generator that writes the call live in the [playground](https://arqampro.com/docs/playground.html) |
480
+ | Intl-style API | `NumberFormat`: `format`, `formatToParts`, `formatRange` |
481
+ | Languages | Arabic (built in) and English (`arqam/en`), each its own engine; more as modules |
482
+ | Documents | Cheque, invoice, receipt and contract wording, in Arabic, English or both (`toClause`) |
483
+ | Dependencies | None; no network calls |
484
+ | Data privacy | 100% client-side: no network requests, so nothing you type leaves your device, in the library and on the website [arqampro.com](https://arqampro.com) |
485
+ | Runs in | Every current browser (modules or a plain `<script>`), Node 14.13+, Deno and bundlers |
486
+ | TypeScript | Full declarations (`dist/*.d.mts`) |
487
+ | Size | Engine 261.4 KB (79.4 KB gzipped), readable; the sub-libraries are separate and load only if you use them |
488
+ | Licence | MIT |
489
+
490
+ </details>
491
+
492
+ ## The calls
493
+
494
+ <details>
495
+ <summary>Show every call</summary>
496
+
497
+ | Call | Gives |
498
+ |---|---|
499
+ | `toWords(number, [locales], [options])` | the words, as `number.toLocaleString(locales, options)`: those of `new NumberFormat(locales, options).format(number)`; an array gives an array |
500
+ | `toParts(number, [options])` | the same words in parts: `prefix`, `sign`, `whole`, `fraction`, `suffix`, `brackets`, `figure`… |
501
+ | `toDate(date, [options])` | a date in words: Gregorian, Hijri or both; styles `words`, `ordinal`, `compact`; Gulf, Levant or Maghreb month names |
502
+ | `toTime(time, [options])` | a time in words: styles `common`, `exact` (صباحًا / مساءً), `h24`, `duration` (ساعتان ونصف); the part of the day; the time zone of an exact moment |
503
+ | `toDateTime(moment, [options])` | a date with its time and time zone, in one phrase |
504
+ | `toFraction(fraction, [options])` | a typed fraction in words: 3/4 → ثلاثة أرباع، 3 1/2 → ثلاثة ونصف، 7/12 → سبعة أجزاء من اثني عشر |
505
+ | `NumberFormat([locales], [options])` | Intl's formatter in words: `format()`, `formatToParts()`, `formatRange()`, `resolvedOptions()`; Intl's rounding (3 places, the currency's minor unit, a whole percent) and `signDisplay` (`always`: «موجب») |
506
+ | `config(options)` | standing options for the calls that follow |
507
+ | `createArqam([options])` | an instance with its own options (two parts of a page, or two users on a server) |
508
+ | `removeTashkeel(text, [options])` | any Arabic text without its tashkeel (113 marks) |
509
+ | `nisba(name, [{feminine}])` | the نسبة adjective of a place name: قطر → قطري، كوريا الشمالية → كوري شمالي |
510
+ | `registerCurrency(code, attributes)` | add or change a currency (or a counted noun) for the session |
511
+ | `registerTimeZone(zone, name)` | give an Arabic name to a time zone that is not on the built-in list |
512
+ | `utils` | the building blocks: `count` any noun, `cardinal`, `ordinal`, `percent`, `scaleName`, `parseDate`, `parseTime`, `parseFraction`, `hijri`, `fromHijri`, `toCase`, `normalize`, `digits`, `markOrder`, `suggest`, and `options` (every option, from one table) |
513
+ | `reset()`, `options()`, `version`, `currencies`, `regions`, `timeZones`, `defaults`, `optionNames` | state and tables |
514
+ | `toBilingual(number, code, [options])` | the amount in Arabic and English, with the figure: `{ar, en, figure}` (with `arqam/en`) |
515
+ | `toLanguages(number, code, languages, [options])` | the same for any languages loaded: `{ar, en, …, figure}` |
516
+ | `toClause(kind, number, code, [options])` | the wording of a cheque, invoice, receipt or contract clause, in Arabic, English or both |
517
+ | `NumberFormat.supportedLocalesOf(locales)` | the locales of a language that is loaded (English with `arqam/en`) |
518
+
519
+ ```js
520
+ arqam.utils.count(11, {single: "سيارة", plural: "سيارات", gender: "feminine"}); // إحدى عشرة سيارةً
521
+ arqam.utils.toCase("السادس والعشرون", "jarr"); // السادس والعشرين
522
+ arqam.removeTashkeel("أَلْفٌ وَمِائَتَانِ"); // ألف ومائتان
523
+ arqam.nisba("قطر"); // قطري
524
+ ```
525
+
526
+ ```js
527
+ import {toWords, toParts, createArqam} from "arqam";
528
+
529
+ toWords("11", {ordinal: "f"}); // الحادية عشرة
530
+ toWords("21", {ordinal: "m", ordinalDefinite: "off"}); // حاد وعشرون (without الـ)
531
+ toWords("1250", {currency: "EGP", wordOrder: "small"}); // خمسون ومائتان وألف جنيه مصري (the classical order)
532
+ toParts("-1250.5", {currency: "EGP"}).whole; // ألف ومائتين وخمسين جنيهًا مصريًا (after سالب)
533
+
534
+ const kw = createArqam({currency: "KWD"});
535
+ kw.toWords("2.5"); // ديناران كويتيان، وخمسمائة فلس
536
+ ```
537
+
538
+ `toWords` is the library's, in Intl's shape: `toWords(number, [locales], [options])`, the same as `arqam(…)` and
539
+ `arqam.toWords(…)`; a currency code in place of the locale makes the number an amount: `toWords(number, "QAR", [options])`.
540
+
541
+ </details>
542
+
543
+ ## Options
544
+
545
+ <details>
546
+ <summary>Show every option</summary>
547
+
548
+ More than sixty (60) options, all explained with their real output in the [manual](https://arqampro.com/docs/arqamAR-manual.html). The ones
549
+ used most:
550
+
551
+ | Option | Values | What it does |
552
+ |---|---|---|
553
+ | `style` | decimal / currency / percent / unit / ordinal / fraction / time / date / dateTime | what the number is (Intl's styles, and Arqam's) |
554
+ | `currency` | an ISO code (`"QAR"`), a registered code, or `""` | the currency (Intl's name), or a plain number |
555
+ | `tashkeel` | alif (default) / none / fatha / tanween / endings / full | the vowel marks: the tanween alif by default (ريالًا), none for plain text, up to full |
556
+ | `ierab` | raf / nasb / jarr | the case ending (الرفع، النصب، الجر) |
557
+ | `legal` | none / auto / full | the form that cannot be misread on a cheque or contract |
558
+ | `ordinal` | masculine / feminine | الأول، الحادية والعشرون… |
559
+ | `prefix`, `suffix` | text | «فقط» … «لا غير» |
560
+ | `brackets`, `numSymbol` | start / end / decimal; code / english / native / sign / name | the figure in brackets, and how the currency shows in it |
561
+ | `decFormat` | auto / words / figures / digits / … / decimal / slash | how the decimals are written |
562
+ | `compact` | on / off | figures with the scale words, as the press writes: 5 ملايين |
563
+ | `arabicNumbers` | eastern / western (on / off) | Arabic-Eastern numbers (٠١٢٣) in the figures |
564
+ | `approx` | about / over / under / atLeast / atMost / few / plus | قرابة، ما يزيد على، أقل من، ما لا يقل عن، ما لا يزيد على، بضعة، نيّف |
565
+ | `locale` | `"ar"`, `"ar-QA"` … the 22 Arab League locales | the region's currency, month names, digits, separators and time zone |
566
+ | `timeZone`, `zoneName` | an IANA name; city / country / offset / both / off | the time zone of an exact moment, and how it is named |
567
+
568
+ Coded values take a readable name or a short code: `tashkeel` none/alif/fatha/tanween/endings/full
569
+ (`""`/`a`/`h`/`t`/`p`/`f`), `ierab` raf/nasb/jarr, `legal` none/auto/full, `numSymbol` code/english/native/sign/name/none (latin and symbol are the earlier names of english and native),
570
+ `decFormat` auto/words/figures/digits/words-words/words-figures/figures-words/figures-figures/decimal/slash, `ordinal`
571
+ masculine/feminine.
572
+
573
+ A misspelt option or a bad value throws a `TypeError` that says what is wrong ("did you mean tashkeel?").
574
+ With `strict: "on"`, a number or date that cannot be written throws too, instead of returning `""`.
575
+
576
+ </details>
577
+
578
+ ## The Intl-style formatter
579
+
580
+ `arqam.NumberFormat`, as `Intl.NumberFormat` but in Arabic words. The locale is optional ("ar"); an object first is
581
+ the options; `new` is optional.
582
+
583
+ ```js
584
+ import {NumberFormat} from "arqam";
585
+ import "arqam/units"; // only for style "unit"
586
+
587
+ new NumberFormat("ar-QA", {style: "currency"}).format(1234.5);
588
+ // ألف ومائتان وأربعة وثلاثون ريالًا قطريًا، وخمسون درهمًا (the currency of the locale's country)
589
+ NumberFormat({style: "percent", maximumFractionDigits: 1}).format(0.125); // اثنا عشر فاصلة خمسة بالمائة
590
+ NumberFormat({style: "unit", unit: "kilometer"}).format(12.5); // اثنا عشر كيلومترًا، وخمسمائة متر
591
+ NumberFormat({style: "ordinal", ordinal: "feminine"}).format(21); // الحادية والعشرون
592
+ [1, 2, 3].map(NumberFormat({style: "ordinal"}).format); // ["الأول", "الثاني", "الثالث"]
593
+ NumberFormat({style: "currency", currency: "QAR"}).formatRange(1000, 2000);
594
+ // من ألف ريال قطري إلى ألفي ريال قطري
595
+ NumberFormat({style: "date"}).formatRange("2026-11-01", "2026-11-15");
596
+ // من الأول إلى الخامس عشر من شهر نوفمبر لعام ألفين وستة وعشرين للميلاد
597
+ ```
598
+
599
+ <p align="left"><img src="https://arqampro.com/images/readme/example-ord.png" width="690" alt="Arqam: the ordinals first, second and third, in coloured words"></p>
600
+
601
+ <p align="left"><img src="https://arqampro.com/images/readme/example-range.png" width="690" alt="Arqam: 1,000 to 2,000 Qatari riyals as a range, in coloured words"></p>
602
+
603
+ <p align="left"><img src="https://arqampro.com/images/readme/example-daterange.png" width="690" alt="Arqam: the dates 1 to 15 November 2026 as a range, in coloured words"></p>
604
+
605
+ Styles: decimal, percent, currency, unit (as in Intl) and ordinal, fraction, time, date, dateTime (Arqam's own).
606
+
607
+ `formatToParts()` gives the words in labelled parts (integer, currency, minorCurrency …) for separate fields.
608
+
609
+ The Intl
610
+ option names (currency, currencyDisplay, numberingSystem, calendar, maximumFractionDigits, roundingMode, signDisplay)
611
+ and every Arqam option work together; Arqam's name wins if both are given.
612
+
613
+ ## Units of measure
614
+
615
+ The units add-on (`arqam/units`, or `src/arqamUnits.js`) brings 304 units: lengths, areas, volumes, weights, speeds,
616
+ times, data, electrical units, pressure, energy, flow, fuel use and more. A unit is found by its Intl name
617
+ (`"kilometer-per-hour"`), its key (`"E04"`) or its Arabic name (`"كيلومتر في الساعة"`).
618
+
619
+ ```js
620
+ arqam.NumberFormat({style: "unit", unit: "kilometer-per-hour"}).format(120); // مائة وعشرون كيلومترًا في الساعة
621
+ ```
622
+
623
+ <p align="left"><img src="https://arqampro.com/images/readme/example-unit.png" width="690" alt="Arqam: 120 kilometres per hour, in coloured words"></p>
624
+
625
+ Each unit is written in the file with named fields (`majorSingle`, `majorPlural`, `majorGender`, `symbolNative` …); the
626
+ file's header and the [manual](https://arqampro.com/docs/arqamAR-developers.html#lib-nf-unitfields) list every field.
627
+
628
+ ## Regions and time zones
629
+
630
+ `locale` reaches every call: the 22 Arab League locales give their currency, month names, digits, separators and time
631
+ zone.
632
+
633
+ An exact moment (ISO with `Z` or an offset, or a `Date`) is moved to the zone and named after its city; 35 world
634
+ airline hubs are named too, and `registerTimeZone()` names any other zone. The zone rules come from the browser or Node
635
+ (IANA); Arqam holds the names only.
636
+
637
+ ```js
638
+ arqam.toDateTime("2026-11-24T06:15:00Z", {locale: "ar-SA"});
639
+ // الرابع والعشرون من شهر نوفمبر لعام ألفين وستة وعشرين للميلاد، الساعة التاسعة وخمس عشرة دقيقةً صباحًا بتوقيت مكة المكرمة
640
+ arqam.toTime("2026-11-24T06:15:00Z", {timeZone: "Europe/London"}); // الساعة السادسة وخمس عشرة دقيقةً صباحًا بتوقيت لندن
641
+ ```
642
+
643
+ <p align="left"><img src="https://arqampro.com/images/readme/example-datetime.png" width="690" alt="Arqam: 24 November 2026, 9:15 in the morning, Makkah time, in coloured words"></p>
644
+
645
+ ## Approximate quantities
646
+
647
+ When the exact figure is not wanted, or not known, `approx` writes the number as an approximation, with the right
648
+ gender and case:
649
+
650
+ ```js
651
+ arqam("2500", "LBP", {approx: "about"}); // قرابة ألفين وخمسمائة ليرة لبنانية
652
+ arqam("2500", "LBP", {approx: "over"}); // ما يزيد على ألفين وخمسمائة ليرة لبنانية
653
+ arqam("2500", "LBP", {approx: "under"}); // أقل من ألفين وخمسمائة ليرة لبنانية
654
+ arqam("2500", "LBP", {approx: "atLeast"}); // ما لا يقل عن ألفين وخمسمائة ليرة لبنانية
655
+ arqam("2500", "LBP", {approx: "atMost"}); // ما لا يزيد على ألفين وخمسمائة ليرة لبنانية
656
+ arqam("5000", "IQD", {approx: "few"}); // بضعة آلاف دينار عراقي
657
+ arqam("300", "DZD", {approx: "few"}); // بضع مئات من الدنانير الجزائرية
658
+ arqam("15", "SDG", {approx: "few"}); // بضعة عشر جنيهًا سودانيًا
659
+ arqam("125", "MAD", {approx: "plus"}); // مائة ونيف وعشرون درهمًا مغربيًا
660
+ ```
661
+
662
+ <p align="left"><img src="https://arqampro.com/images/readme/example-approx6.png" width="690" alt="Arqam: six ways to write an approximate amount, in coloured words"></p>
663
+
664
+ <p align="left"><img src="https://arqampro.com/images/readme/example-approx.png" width="690" alt="Arqam: about 125 Moroccan dirhams (نيف), in coloured words"></p>
665
+
666
+ «بضع» (`few`) stands for 3 to 9 of something: give 5, 15, 25, 500 or 5000.
667
+
668
+ «نيّف» (`plus`) stands for 1 to 9 above a ten or a hundred: give 25, 125 or 103.
669
+
670
+ A number that neither fits gives `""`; with `strict: "on"` it throws a `RangeError`.
671
+
672
+ ## Words back to numbers
673
+
674
+ `arqam/words` reads Arabic number words in any text (dialects too), with fractions, currencies and a cheque check. It is
675
+ a sub-library: it uses the engine's own functions, and importing it brings the engine with it.
676
+
677
+ ```js
678
+ import wordsToNumbers, {find, verify} from "arqam/words";
679
+
680
+ wordsToNumbers("لدي ألفان وخمسمائة ريال وخمستاشر كتاب"); // لدي 2500 ريال و15 كتاب
681
+ wordsToNumbers("ألف، ومائتان وخمسون ريالًا قطريًا، وخمسون درهمًا", {currency: "code"}); // 1250.50 QAR
682
+ verify("فقط ألف ومائتان وخمسون ريالًا قطريًا لا غير", "1250", {currency: "QAR"}).ok; // true
683
+ verify("ألف ريال قطري، وخمسون درهما", "1250.75", {currency: "QAR"}).issue; // both
684
+ verify("ألف ريال قطري، وخمسون درهما", "1250.75", {currency: "QAR"}).difference; // -250.25
685
+ verify("ألف ريال قطري، وخمسون درهما", "1250.75", {currency: "QAR"}).expectedWords;
686
+ // ألف ومائتان وخمسون ريالًا قطريًا، وخمسة وسبعون درهمًا
687
+ ```
688
+
689
+ <p align="left"><img src="https://arqampro.com/images/readme/example-w2n.png" width="690" alt="Arqam: Arabic words read back as numbers, in coloured words"></p>
690
+
691
+ When the words and the figure differ, `verify()` says how: `issue` is "whole" (the whole units differ), "subunit" (only
692
+ the fraction), "both", "currency", "none" (no amount in the words) or "several"; `difference` is what the words say
693
+ minus the figure; `expectedWords` is the figure in words. A mismatch is reported, never judged.
694
+
695
+ Once it is loaded, the engine has both directions: `arqam.fromWords(text)`, `arqam.findNumbers(text)` and
696
+ `arqam.verify(words, number)`.
697
+
698
+ ## Explain the grammar
699
+
700
+ `arqam/explain` (also a sub-library) gives every word with its إعراب, the reason and the rule, as the «اشرح» button on
701
+ the page.
702
+
703
+ ```js
704
+ import {explain} from "arqam/explain";
705
+ explain("13", {currency: "SYP"}).words[0].why; // الجزء الأول من 13 يخالف المعدود: «ليرة» مؤنث فجاء بلا تاء.
706
+ ```
707
+
708
+
709
+ <p align="left"><img src="https://arqampro.com/images/readme/grammar.png" width="760" alt="arqam/explain: each word of 23 Qatari riyals with its case and rule"></p>
710
+
711
+ ## Arabic-Eastern and Arabic-Western numbers
712
+
713
+ <details>
714
+ <summary>Show how digits are read and written</summary>
715
+
716
+ The figures in brackets are Arabic-Western numbers (0123456789) by default; `arabicNumbers: "eastern"` (or `"on"`, or
717
+ `-u-nu-arab` in the locale) writes Arabic-Eastern numbers (٠١٢٣٤٥٦٧٨٩) with the Arabic separators. A region
718
+ (`locale`) gives Arabic-Eastern numbers in Egypt, Iraq, Jordan, Palestine, Saudi Arabia, Sudan, Syria and Yemen, and
719
+ Arabic-Western numbers everywhere else; `arabicNumbers` changes it either way:
720
+
721
+ ```js
722
+ arqam.toWords("1250.5", "ar-SA", {style: "currency", brackets: "end"}); // ألف ومائتان وخمسون ريالًا سعوديًا، وخمسون هللةً (١٬٢٥٠٫٥٠ SAR)
723
+ arqam.toWords("1250.5", "ar-KW", {style: "currency", brackets: "end"}); // ألف ومائتان وخمسون دينارًا كويتيًا، وخمسمائة فلس (1,250.500 KWD)
724
+ arqam.toWords("1250.5", "ar-KW", {style: "currency", arabicNumbers: "eastern", brackets: "end"});
725
+ // ألف ومائتان وخمسون دينارًا كويتيًا، وخمسمائة فلس (١٬٢٥٠٫٥٠٠ KWD)
726
+ ```
727
+
728
+ The Arabic separators:
729
+
730
+ - **Arabic decimal separator (`٫` / `U+066B`):** used in formal and typeset Arabic numbers, e.g. `٣٫١`
731
+ - **Arabic thousands separator (`٬` / `U+066C`):** groups large numbers into thousands, e.g. `١٬٠٠٠٬٠٠٠`
732
+
733
+ ```js
734
+ arqam.toWords("1250.50", "USD", {brackets: "end", arabicNumbers: "on"});
735
+ // ألف ومائتان وخمسون دولارًا أمريكيًا، وخمسون سنتًا (١٬٢٥٠٫٥٠ USD)
736
+ ```
737
+
738
+ <p align="left"><img src="https://arqampro.com/images/readme/example-eastern.png" width="690" alt="Arqam: 1250.50 US dollars with the figure in Arabic numerals, in coloured words"></p>
739
+
740
+ </details>
741
+
742
+ ## Languages
743
+
744
+ Each language is an engine of its own, loaded with its module, and reached through `arqam` by its locale. Each has
745
+ its own README and manual:
746
+
747
+ | Language | Module | Locales | README | Manual |
748
+ |---|---|---|---|---|
749
+ | Arabic | built in: the default | `ar`, `ar-QA`, `ar-SA` … (the region gives its currency, digits and month names) | [this README](#the-arabic-engine-arqamar) | [Arabic](https://arqampro.com/docs/arqamAR-manual.html) |
750
+ | English | `arqam/en` | `en-US` (no «and»), `en-GB`, `en-IN` (lakh and crore) … | [en/README.md](https://github.com/MohsenAlyafei/arqam/blob/master/en/README.md) | [English](https://arqampro.com/docs/arqamEN-manual.html) |
751
+
752
+ What joins the languages is in the library only: amounts in two languages at once and the wording of documents.
753
+ The number of decimals of each currency comes from Arqam's one currency table, so every language agrees on it.
754
+ [The library's manual](https://arqampro.com/docs/manual.html) covers these.
755
+
756
+ ```js
757
+ import arqam from "arqam";
758
+ import "arqam/en";
759
+
760
+ arqam.NumberFormat.supportedLocalesOf(["ar-QA", "en-GB", "fr-FR"]); // ["ar-QA","en-GB"]
761
+ ```
762
+
763
+ ## Two languages at once
764
+
765
+ Both languages at once, as on a bilingual cheque or contract:
766
+
767
+ ```js
768
+ arqam.toBilingual("1250.50", "QAR").ar; // فقط ألف ومائتان وخمسون ريالًا قطريًا، وخمسون درهمًا لا غير
769
+ arqam.toBilingual("1250.50", "QAR").en; // One Thousand Two Hundred and Fifty Qatari Riyals and Fifty Dirhams Only
770
+ arqam.toBilingual("1250.50", "QAR").figure; // 1,250.50 QAR
771
+ ```
772
+
773
+ <p align="left"><img src="https://arqampro.com/images/readme/example-bi.png" width="690" alt="Arqam: 1250.50 Qatari riyals in Arabic and English, in coloured words"></p>
774
+
775
+ `toBilingual()` writes «فقط … لا غير» and "Only" (`only: "off"` leaves them out), the Arabic with the tanween on the
776
+ alif as on cheques (`tashkeel` changes it), and the English in UK style with "Only" at the end (`style: "us"` leaves out
777
+ the "and", `onlyEn: "start"` puts "Only" first).
778
+
779
+ `toLanguages(number, code, ["ar", "en"])` does the same for any languages that are loaded.
780
+
781
+ ## Documents: cheques, invoices, receipts, contracts
782
+
783
+ `toClause(kind, number, code, [options])` writes the wording of a document around the amount: `"cheque"`, `"invoice"`,
784
+ `"receipt"` or `"contract"` (a contract article). It gives `{text, lines, words, figure}`; `lang: "en"` gives it in
785
+ English, `lang: ["ar", "en"]` in both. The wording is Arqam's own, the same as the «مستندات» mode of the
786
+ [Arqam page](https://arqampro.com); it does not claim to follow any bank's or regulator's form.
787
+
788
+ ```js
789
+ arqam.toClause("cheque", "15400.75", "QAR", {payee: "شركة الخليج للتجارة"}).lines[1];
790
+ // مبلغًا وقدره: فقط خمسة عشر ألفًا وأربعمائة ريال قطري، وخمسة وسبعون درهمًا لا غير (15,400.75 QAR)
791
+ arqam.toClause("cheque", "15400.75", "QAR", {payee: "Gulf Trading Co.", lang: "en"}).lines[1];
792
+ // The sum of: Fifteen Thousand Four Hundred Qatari Riyals and Seventy-Five Dirhams Only (QAR 15,400.75)
793
+ ```
794
+
795
+ Options: `payee`, `for` (what the amount is for), `ref` (the cheque, invoice or receipt number), `date` (ISO text or a
796
+ `Date`), `hijri` (the Hijri date beside it), `clause` (the article number of a contract), `only` («فقط … لا غير», on by
797
+ default, off for a contract, where it would sit inside a sentence), `tashkeel` (the Arabic; the tanween on the alif by
798
+ default) and `lang`.
799
+
800
+
801
+ <p align="left"><img src="https://arqampro.com/images/readme/cheque.png" width="720" alt="A cheque for 15,400.75 QAR with the amount in coloured Arabic words, written by Arqam"></p>
802
+
803
+ ## Adding a language
804
+
805
+ A new language (French, German …) is a new engine and its documents; the library does not change:
806
+
807
+ 1. the engine `arqamXX.js` (XX the ISO 639-1 code in capitals) with its `NumberFormat`, that puts itself in the
808
+ library's table of languages (`globalThis[Symbol.for("arqam.languages")].xx`), so its locales reach it;
809
+ 2. its README, `xx/README.md`, and its manual, `docs/arqamXX-manual.html`, and its line in the table above;
810
+ 3. its document wording, if it writes documents, its tests, and its module `arqam/xx`.
811
+
812
+ See [the library's manual](https://arqampro.com/docs/manual.html#s6).
813
+
814
+ ## TypeScript, browsers, Node and size
815
+
816
+ - **TypeScript:** declarations for the Arabic and English engines, the reader, «اشرح» and the units (`dist/*.d.mts`); a
817
+ misspelt option is a compile error.
818
+ - **Runs in** every current browser, Node 14.13+, Deno and bundlers. No network, no globals in the modules (the plain
819
+ script defines `arqam` and its Arabic engine `arqamAR`, and nothing else), no dependencies.
820
+ - **Languages:** Arabic is built in; English is the module `arqam/en` ([`en/`](https://github.com/MohsenAlyafei/arqam/blob/master/en/)); see [Languages](#languages) and [en/README.md](https://github.com/MohsenAlyafei/arqam/blob/master/en/README.md).
821
+ - **Size (gzipped in brackets):** engine 261.4 KB (79.4 KB), words to numbers 107.2 KB (29.5 KB), «اشرح» 120.0 KB
822
+ (30.9 KB), units 59.1 KB (9.8 KB), English 57.4 KB (18.8 KB). Load only what you use.
823
+
824
+ ## Documentation and online tools
825
+
826
+ | | |
827
+ |---|---|
828
+ | **[The Arqam page](https://arqampro.com)** | type a number and see its words, with every option; batch conversion; «اشرح» |
829
+ | **[The manuals](https://arqampro.com/docs/manual.html)** | the library; [Arabic](https://arqampro.com/docs/arqamAR-manual.html): every call, option and error with its real output, and more than 500 questions; [English](https://arqampro.com/docs/arqamEN-manual.html) |
830
+ | **[The playground](https://arqampro.com/docs/playground.html)** | run the library in your browser, with ready examples for every feature |
831
+ | **[Speed](https://arqampro.com/docs/benchmark.html)** | how fast it writes numbers of 10 to 1,000,000 digits; `node tools/benchmark.js` measures your machine |
832
+ | **[Download](https://arqampro.com/download/)** | the modules and TypeScript declarations, without npm |
833
+ | **[docs/DEVELOPER.md](https://github.com/MohsenAlyafei/arqam/blob/master/docs/DEVELOPER.md)** | how the library is built and tested |
834
+
835
+ ### The website: arqampro.com
836
+
837
+ [arqampro.com](https://arqampro.com) is the home of Arqam. Everything on it runs in your browser on this library, with
838
+ no sign-up and no network calls once the page is open.
839
+
840
+ - **The Arqam page**, in three modes:
841
+ - «سريع» (Quick): one box for everything. Type a number, an amount (`1250 QAR`), a date, a time, a fraction, a unit
842
+ or Arabic words, and the type is recognised.
843
+ - «احترافي» (Professional): every option of the library, other forms of the same words, a check that reads the words
844
+ back, and «اشرح», the grammar of every word.
845
+ - «مستندات» (Documents): the amount placed in a cheque, an invoice, a contract clause or a receipt, ready to copy or
846
+ print.
847
+ - Also: batch conversion with Excel and CSV export, recent conversions, the 22 Arab regions, and dark mode.
848
+ - **The manuals**: the library, Arabic (every call, option and error with its real output, and more than 500 questions
849
+ and answers) and English.
850
+ - **The playground** (below).
851
+ - **Download**: the modules and the TypeScript declarations, without npm.
852
+
853
+ ### The playground: a live engine and a code editor
854
+
855
+ [The playground](https://arqampro.com/docs/playground.html) is the whole library running in your browser, the same
856
+ engine as the npm package, with a code editor beside it:
857
+
858
+ - **Builder:** choose a call (amounts, numbers, ordinals, dates, times, fractions, ranges, approximate quantities,
859
+ time zones) and its options. The playground writes the code, shows it under «The code for this result», and runs it.
860
+ - **Code editor:** write your own code against `arqam`. It is coloured as you type, an Arabic string reads right to
861
+ left, and Ctrl+Enter (or ▶ Run) runs it, with one result for each line. A loop that never ends is stopped rather than
862
+ freezing the tab.
863
+ - **Result views:** the words, their parts (`formatToParts`), the JSON, the words read back into numbers, «اشرح» (the
864
+ grammar of every word), and the same call in every case and tashkeel mode side by side.
865
+ - **Examples** for beginners and advanced users, one click each, plus Copy code, Copy words and a share link that
866
+ opens the playground with your code.
867
+
868
+ ## This repository
869
+
870
+ | Folder | What is in it |
871
+ |---|---|
872
+ | [`src/`](https://github.com/MohsenAlyafei/arqam/blob/master/src/) | the library as plain scripts: `arqamAR.js`, `arqamWordsToNumbers.js`, `arqamExplain.js`, `arqamUnits.js` |
873
+ | [`dist/`](https://github.com/MohsenAlyafei/arqam/blob/master/dist/) | the ES modules, TypeScript declarations and `SRI.txt` (what npm installs) |
874
+ | [`types/`](https://github.com/MohsenAlyafei/arqam/blob/master/types/) | the TypeScript declarations (copied into `dist/` by the build) |
875
+ | [`ar/`](https://github.com/MohsenAlyafei/arqam/blob/master/ar/) | the README of the Arabic engine `arqamAR` (its code is in `src/`) |
876
+ | [`en/`](https://github.com/MohsenAlyafei/arqam/blob/master/en/) | the English engine `arqamEN`, and its README |
877
+ | [`extras/`](https://github.com/MohsenAlyafei/arqam/blob/master/extras/) | standalone helpers (scale names, ordinals, tashkeel and hamza removal, نسبة) and earlier work |
878
+ | [`tests/`](https://github.com/MohsenAlyafei/arqam/blob/master/tests/) | the library tests and proofs: `node tests/arqam.test.js` |
879
+ | [`tools/`](https://github.com/MohsenAlyafei/arqam/blob/master/tools/) | the build tools for `dist/` and the units add-on |
880
+ | [`js/`](https://github.com/MohsenAlyafei/arqam/blob/master/js/) | the currency and unit tables the units add-on and the tests are built from (shared with the page) |
881
+ | [`docs/`](https://github.com/MohsenAlyafei/arqam/blob/master/docs/) | `DEVELOPER.md` |
882
+
883
+ The Arqam page, manual and playground are published on [arqampro.com](https://arqampro.com).
884
+
885
+ ## Licence and author
886
+
887
+ MIT licence (see [LICENSE](https://github.com/MohsenAlyafei/arqam/blob/master/LICENSE)). © Mohsen Alyafei (محسن اليافعي).
888
+