arqam 1.1.2 → 2.0.1

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