arqam 2.0.0 → 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 +293 -286
- package/package.json +7 -2
package/README.md
CHANGED
|
@@ -19,7 +19,9 @@
|
|
|
19
19
|
<a href="https://arqampro.com"><b>Try it online</b></a> ·
|
|
20
20
|
<a href="https://arqampro.com/docs/manual.html"><b>Manual</b></a> ·
|
|
21
21
|
<a href="https://arqampro.com/docs/playground.html"><b>Playground</b></a> ·
|
|
22
|
-
<a href="https://arqampro.com/download/"><b>Download</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>
|
|
23
25
|
</p>
|
|
24
26
|
|
|
25
27
|
<p align="center">
|
|
@@ -34,21 +36,21 @@
|
|
|
34
36
|
## Arabic numbers in words, written the way a grammarian would
|
|
35
37
|
|
|
36
38
|
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
|
|
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.
|
|
39
41
|
|
|
40
42
|
| Why Arqam | What you get |
|
|
41
43
|
|---|---|
|
|
42
|
-
|
|
|
43
|
-
|
|
|
44
|
-
|
|
|
45
|
-
|
|
|
46
|
-
|
|
|
47
|
-
|
|
|
48
|
-
|
|
|
49
|
-
|
|
|
50
|
-
|
|
|
51
|
-
|
|
|
44
|
+
| **Correct Arabic, every 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 for cheques and invoices** | 188 currencies with their subunits, «فقط … لا غير», the legal wording, and the same amount in English |
|
|
46
|
+
| **No size 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 than amounts** | Ordinals up to 999,999, Hijri and Gregorian dates, times and fractions |
|
|
48
|
+
| **Words back to numbers** | `arqam/words` reads Arabic amounts back into figures, to check a document, including local dialects: «ألفين وخمسمية» as 2500 |
|
|
49
|
+
| **Explains its own grammar** | `arqam/explain` gives each word's case (الإعراب), the reason and the rule: for schools, students and proofreaders |
|
|
50
|
+
| **Units of measure** | `arqam/units`: 304 units, by their international or Arabic names |
|
|
51
|
+
| **Arabic and English** | `arqam/en` writes the same amount in UK or US English, for bilingual documents |
|
|
52
|
+
| **The Golden 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 and private** | Pure JavaScript, no dependencies, nothing sent over the network, TypeScript types, MIT licence |
|
|
52
54
|
|
|
53
55
|
**Try it in ten seconds:**
|
|
54
56
|
|
|
@@ -66,13 +68,16 @@ Or use it online, free and with nothing to install, at **[arqampro.com](https://
|
|
|
66
68
|
|
|
67
69
|
```js
|
|
68
70
|
import arqam from "arqam";
|
|
69
|
-
import "arqam/en";
|
|
71
|
+
import "arqam/en"; // English: adds itself to arqam, so it needs no name
|
|
70
72
|
|
|
71
|
-
arqam("1250.50", "ar-
|
|
72
|
-
|
|
73
|
-
arqam(1250
|
|
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); // ألف ومائتان وخمسون
|
|
74
78
|
// a BigInt, for whole numbers beyond a JavaScript number's exact range:
|
|
75
|
-
arqam(9007199254740993n, "SAR");
|
|
79
|
+
arqam(9007199254740993n, "SAR");
|
|
80
|
+
// تسعة كوادرليونات وسبعة تريليونات ومائة وتسعة وتسعون مليارًا ومائتان وأربعة وخمسون مليونًا وسبعمائة وأربعون ألفًا وتسعمائة وثلاثة وتسعون ريالًا سعوديًا
|
|
76
81
|
```
|
|
77
82
|
|
|
78
83
|
<p align="left"><img src="https://arqampro.com/images/readme/example-big.png" width="690" alt="Arqam: arqam(9007199254740993n, "SAR"), in coloured words"></p>
|
|
@@ -83,7 +88,7 @@ same as `arqam.toWords`, and a currency code in place of the locale makes the nu
|
|
|
83
88
|
|
|
84
89
|
```js
|
|
85
90
|
arqam("1250.50", "DZD"); // ألف ومائتان وخمسون دينارًا جزائريًا، وخمسون سنتيمًا
|
|
86
|
-
arqam("2", "DZD");
|
|
91
|
+
arqam("2", "DZD"); // ديناران جزائريان
|
|
87
92
|
arqam("2", "DZD", {prefix: "فقط", suffix: "لا غير"}); // فقط ديناران جزائريان اثنان لا غير
|
|
88
93
|
```
|
|
89
94
|
|
|
@@ -95,118 +100,51 @@ is said twice; `emphasisOneTwo: "on"` writes it always.
|
|
|
95
100
|
The locale chooses the language, and
|
|
96
101
|
Intl's option names, defaults and methods are kept; Arqam's own options sit beside them.
|
|
97
102
|
|
|
98
|
-
>
|
|
99
|
-
>
|
|
100
|
-
> `
|
|
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`.
|
|
101
106
|
|
|
102
107
|
<p align="center">
|
|
103
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>
|
|
104
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>
|
|
105
110
|
</p>
|
|
106
111
|
|
|
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¤cy=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=…¤cy=…` | 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&"¤cy=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
112
|
## Contents
|
|
146
113
|
|
|
147
|
-
|
|
|
114
|
+
| **Get started** | **The Arabic engine** | **Languages and more** |
|
|
148
115
|
|:---|:---|:---|
|
|
149
|
-
| [Why Arqam](#why-arqam)<br>[Why not ask an AI model?](#why-not-ask-an-ai-model-to-do-the-job)<br>[
|
|
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) |
|
|
150
117
|
|
|
151
118
|
<!-- gen:why -->
|
|
152
119
|
## Why Arqam
|
|
153
120
|
|
|
154
|
-
Many websites and libraries turn numbers into Arabic words, and many get the grammar wrong: the gender of the number
|
|
155
|
-
|
|
156
|
-
|
|
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
|
|
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".
|
|
176
124
|
|
|
177
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.
|
|
178
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.
|
|
179
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.
|
|
180
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.
|
|
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
|
|
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.
|
|
182
133
|
<!-- /gen:why -->
|
|
183
134
|
|
|
184
135
|
## Why not ask an AI model to do the job?
|
|
185
136
|
|
|
186
|
-
AI models are useful for many things, but
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
- **
|
|
190
|
-
|
|
191
|
-
- **
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
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.
|
|
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.
|
|
210
148
|
|
|
211
149
|
```js
|
|
212
150
|
arqam.toWords("432215.750", "KWD", {ierab: "nasb", tashkeel: "full"});
|
|
@@ -215,78 +153,6 @@ arqam.toWords("432215.750", "KWD", {ierab: "nasb", tashkeel: "full"});
|
|
|
215
153
|
|
|
216
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>
|
|
217
155
|
|
|
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
156
|
## Install
|
|
291
157
|
|
|
292
158
|
```
|
|
@@ -304,6 +170,50 @@ The modules are minified, each under a banner with its version and licence; the
|
|
|
304
170
|
|
|
305
171
|
`dist/SRI.txt` has an integrity hash for every module.
|
|
306
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
|
+
|
|
307
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/),
|
|
308
218
|
or load the plain scripts in [`src/`](https://github.com/MohsenAlyafei/arqam/blob/master/src/) with a `<script>` tag:
|
|
309
219
|
|
|
@@ -319,7 +229,7 @@ or load the plain scripts in [`src/`](https://github.com/MohsenAlyafei/arqam/blo
|
|
|
319
229
|
|
|
320
230
|
```js
|
|
321
231
|
import arqam from "arqam";
|
|
322
|
-
import "arqam/en";
|
|
232
|
+
import "arqam/en"; // English: adds itself to arqam, so it needs no name
|
|
323
233
|
|
|
324
234
|
arqam("1250.50", "ar-SA", {style: "currency", tashkeel: "full", prefix: "فقط", suffix: "لا غير", brackets: "end", numberingSystem: "latn"});
|
|
325
235
|
// فَقَطْ أَلْفٌ وَمِائَتَانِ وَخَمْسُونَ رِيَالًا سُعُودِيًّا، وَخَمْسُونَ هَلَلَةً لَا غَيْرْ (1,250.50 SAR)
|
|
@@ -329,10 +239,10 @@ arqam.toDate("18/11/2026", {calendar: "both", tashkeel: "full"});
|
|
|
329
239
|
// الثَّامِنَ عَشَرَ مِنْ شَهْرِ نُوفَمْبِرَ لِعَامِ أَلْفَيْنِ وَسِتَّةٍ وَعِشْرِينَ لِلْمِيلَادِ، الْمُوَافِقُ الثَّامِنَ مِنْ شَهْرِ جُمَادَى الْآخِرَةِ لِعَامِ أَلْفٍ وَأَرْبَعِمِائَةٍ وَثَمَانِيَةٍ وَأَرْبَعِينَ لِلْهِجْرَةِ
|
|
330
240
|
arqam("1250.50", "en-GB", {style: "currency", currency: "QAR", only: "end", brackets: "end"});
|
|
331
241
|
// 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"});
|
|
242
|
+
arqam("1.23456"); // واحد، ومائتان وخمسة وثلاثون جزءًا من الألف
|
|
243
|
+
arqam("1.005", "ar-QA", {style: "currency"}); // ريال قطري، ودرهم
|
|
334
244
|
arqam("1.005", "ar-QA", {style: "currency", roundingMode: "trunc"}); // ريال قطري
|
|
335
|
-
arqam("5", {signDisplay: "always"});
|
|
245
|
+
arqam("5", {signDisplay: "always"}); // موجب خمسة
|
|
336
246
|
```
|
|
337
247
|
|
|
338
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>
|
|
@@ -342,15 +252,17 @@ As JavaScript's `Intl.NumberFormat`, one `arqam.NumberFormat` writes every langu
|
|
|
342
252
|
are there too.
|
|
343
253
|
|
|
344
254
|
```js
|
|
345
|
-
new arqam.NumberFormat("ar-QA", {style: "currency", currency: "QAR"}).format(1250.5);
|
|
346
|
-
|
|
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
|
|
347
259
|
```
|
|
348
260
|
|
|
349
261
|
Pass amounts as text (`"1250.50"`): a JS number keeps only about 16 significant digits.
|
|
350
262
|
|
|
351
|
-
The rounding is Intl's: 3
|
|
352
|
-
|
|
353
|
-
`
|
|
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"`.
|
|
354
266
|
|
|
355
267
|
Each language has its own options beside Intl's: see
|
|
356
268
|
[Arabic](#the-arabic-engine-arqamar) and [English](https://github.com/MohsenAlyafei/arqam/blob/master/en/README.md).
|
|
@@ -389,73 +301,123 @@ And more:
|
|
|
389
301
|
```js
|
|
390
302
|
arqam("1250.50", "DZD", {prefix: "فقط", suffix: "لا غير"});
|
|
391
303
|
// فقط ألف ومائتان وخمسون دينارًا جزائريًا، وخمسون سنتيمًا لا غير
|
|
392
|
-
arqam.toWords("2000000", "DZD", {ierab: "jarr"});
|
|
393
|
-
arqam.toWords("2500", "LBP", {approx: "about"});
|
|
304
|
+
arqam.toWords("2000000", "DZD", {ierab: "jarr"}); // مليوني دينار جزائري
|
|
305
|
+
arqam.toWords("2500", "LBP", {approx: "about"}); // قرابة ألفين وخمسمائة ليرة لبنانية
|
|
394
306
|
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%");
|
|
307
|
+
arqam.toWords("101000", {legal: "full"}); // مائة ألف وألف
|
|
308
|
+
arqam.toWords("21", {style: "ordinal", ordinal: "feminine"}); // الحادية والعشرون
|
|
309
|
+
arqam.toWords("25%"); // خمسة وعشرون بالمائة
|
|
398
310
|
|
|
399
311
|
"في " + arqam.toDate("26/11/2026", {ierab: "jarr"});
|
|
400
312
|
// في السادس والعشرين من شهر نوفمبر لعام ألفين وستة وعشرين للميلاد
|
|
401
|
-
arqam.toTime("15:45");
|
|
402
|
-
arqam.toTime("15:45", {timeParts: "on"});
|
|
403
|
-
arqam.toFraction("3 1/2");
|
|
404
|
-
arqam.toFraction("3/4");
|
|
313
|
+
arqam.toTime("15:45"); // الساعة الثالثة وخمس وأربعون دقيقةً عصرًا
|
|
314
|
+
arqam.toTime("15:45", {timeParts: "on"}); // الساعة الرابعة إلا الربع عصرًا
|
|
315
|
+
arqam.toFraction("3 1/2"); // ثلاثة ونصف
|
|
316
|
+
arqam.toFraction("3/4"); // ثلاثة أرباع
|
|
405
317
|
```
|
|
406
318
|
|
|
407
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>
|
|
408
320
|
|
|
409
321
|
Arabic-Western and Arabic-Eastern numbers are both accepted, with `-` before and `%` after.
|
|
410
322
|
|
|
411
|
-
##
|
|
323
|
+
## Recipes
|
|
412
324
|
|
|
413
|
-
|
|
414
|
-
the same Arabic words:
|
|
325
|
+
One call for each common task. Every line is run by the README test.
|
|
415
326
|
|
|
416
327
|
```js
|
|
417
328
|
import arqam from "arqam";
|
|
418
|
-
//
|
|
419
|
-
import
|
|
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 ريال
|
|
420
357
|
```
|
|
421
358
|
|
|
422
|
-
|
|
359
|
+
## Web API: tafqeet from any program
|
|
423
360
|
|
|
424
|
-
|
|
425
|
-
|
|
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.
|
|
426
364
|
|
|
427
|
-
|
|
428
|
-
|
|
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.
|
|
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.
|
|
433
367
|
|
|
434
|
-
|
|
368
|
+
```text
|
|
369
|
+
https://api.arqampro.com/v1/words?n=1250.50¤cy=SAR
|
|
370
|
+
```
|
|
435
371
|
|
|
436
|
-
|
|
372
|
+
```json
|
|
373
|
+
{ "input": "1250.50", "words": "ألف ومائتان وخمسون ريالًا سعوديًا، وخمسون هللةً", "version": "1.90" }
|
|
374
|
+
```
|
|
437
375
|
|
|
438
|
-
|
|
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.
|
|
376
|
+
`version` is the Arabic engine's version (`arqamEngine` in `package.json`), not the npm package's.
|
|
442
377
|
|
|
443
|
-
|
|
378
|
+
| Call | Gives |
|
|
379
|
+
|---|---|
|
|
380
|
+
| `/v1/words?n=…` | a number or amount in Arabic words |
|
|
381
|
+
| `/v1/bilingual?n=…¤cy=…` | 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 |
|
|
444
387
|
|
|
445
|
-
|
|
446
|
-
|
|
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&"¤cy=SAR&format=text")
|
|
393
|
+
```
|
|
447
394
|
|
|
448
|
-
|
|
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"])
|
|
449
399
|
```
|
|
450
400
|
|
|
401
|
+
Every call, its options and examples for PHP, C# and curl: [the API page](https://arqampro.com/en/tafqeet/api/).
|
|
451
402
|
|
|
452
|
-
|
|
403
|
+
## The Arabic engine (arqamAR)
|
|
453
404
|
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
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`).
|
|
459
421
|
|
|
460
422
|
## Specifications
|
|
461
423
|
|
|
@@ -464,27 +426,27 @@ into numbers, checks words against their figure, and explains the grammar of eve
|
|
|
464
426
|
|
|
465
427
|
| Feature | Arqam |
|
|
466
428
|
|---|---|
|
|
467
|
-
| Whole digits | No limit
|
|
468
|
-
| Decimal places | No limit
|
|
469
|
-
| Input digits | Arabic-Western (0–9), Arabic-Eastern (٠–٩) and Persian (۰–۹)
|
|
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"` |
|
|
470
432
|
| Scales | Arabic (مليار), short (بليون) and long (European), with `scale` |
|
|
471
433
|
| Output numerals | Arabic-Western or Arabic-Eastern, with `arabicNumbers` |
|
|
472
434
|
| Currencies | 188 built in, plus your own with `registerCurrency` |
|
|
473
435
|
| Units of measure | 304 built in (`arqam/units`) |
|
|
474
|
-
| Ordinals | 1 to 999,999
|
|
475
|
-
| Approximate quantities | Seven forms with `approx
|
|
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 (نيّف) |
|
|
476
438
|
| Dates and times | Gregorian and Hijri (Umm al-Qura) dates, times, time zones, styles, durations and ranges |
|
|
477
|
-
| Grammar | Gender polarity of 3–10
|
|
478
|
-
| Words back to numbers, `verify()` | Reads Fuṣḥā (الفصحى) and colloquial Arabic
|
|
479
|
-
| Grammar explainer |
|
|
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 |
|
|
480
442
|
| Intl-style API | `NumberFormat`: `format`, `formatToParts`, `formatRange` |
|
|
481
443
|
| Languages | Arabic (built in) and English (`arqam/en`), each its own engine; more as modules |
|
|
482
444
|
| Documents | Cheque, invoice, receipt and contract wording, in Arabic, English or both (`toClause`) |
|
|
483
445
|
| Dependencies | None; no network calls |
|
|
484
|
-
| Data privacy |
|
|
446
|
+
| Data privacy | Everything runs on your device. Nothing you type is sent anywhere, in the library or on [arqampro.com](https://arqampro.com) |
|
|
485
447
|
| Runs in | Every current browser (modules or a plain `<script>`), Node 14.13+, Deno and bundlers |
|
|
486
448
|
| TypeScript | Full declarations (`dist/*.d.mts`) |
|
|
487
|
-
| Size | Engine 261.4 KB (79.4 KB gzipped)
|
|
449
|
+
| Size | Engine 261.4 KB (79.4 KB gzipped). Each add-on is a separate file, loaded only if you use it |
|
|
488
450
|
| Licence | MIT |
|
|
489
451
|
|
|
490
452
|
</details>
|
|
@@ -496,47 +458,49 @@ into numbers, checks words against their figure, and explains the grammar of eve
|
|
|
496
458
|
|
|
497
459
|
| Call | Gives |
|
|
498
460
|
|---|---|
|
|
499
|
-
| `toWords(number, [locales], [options])` | the words, as `number.toLocaleString(locales, options)
|
|
461
|
+
| `toWords(number, [locales], [options])` | the words, as `number.toLocaleString(locales, options)` would give figures. An array gives an array |
|
|
500
462
|
| `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
|
|
502
|
-
| `toTime(time, [options])` | a time in words
|
|
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 |
|
|
503
465
|
| `toDateTime(moment, [options])` | a date with its time and time zone, in one phrase |
|
|
504
|
-
| `toFraction(fraction, [options])` | a
|
|
505
|
-
| `NumberFormat([locales], [options])` | Intl's formatter in words: `format()`, `formatToParts()`, `formatRange()
|
|
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 |
|
|
506
468
|
| `config(options)` | standing options for the calls that follow |
|
|
507
|
-
| `createArqam([options])` | an instance with its own options
|
|
469
|
+
| `createArqam([options])` | an instance with its own options, for example one per user on a server |
|
|
508
470
|
| `removeTashkeel(text, [options])` | any Arabic text without its tashkeel (113 marks) |
|
|
509
471
|
| `nisba(name, [{feminine}])` | the نسبة adjective of a place name: قطر → قطري، كوريا الشمالية → كوري شمالي |
|
|
510
472
|
| `registerCurrency(code, attributes)` | add or change a currency (or a counted noun) for the session |
|
|
511
473
|
| `registerTimeZone(zone, name)` | give an Arabic name to a time zone that is not on the built-in list |
|
|
512
|
-
| `utils` | the building blocks
|
|
474
|
+
| `utils` | the building blocks, such as `count` (any counted noun), `ordinal`, `parseDate`, `hijri`, `toCase` and `options` (every option) |
|
|
513
475
|
| `reset()`, `options()`, `version`, `currencies`, `regions`, `timeZones`, `defaults`, `optionNames` | state and tables |
|
|
514
476
|
| `toBilingual(number, code, [options])` | the amount in Arabic and English, with the figure: `{ar, en, figure}` (with `arqam/en`) |
|
|
515
477
|
| `toLanguages(number, code, languages, [options])` | the same for any languages loaded: `{ar, en, …, figure}` |
|
|
516
|
-
| `toClause(kind, number, code, [options])` | the wording
|
|
478
|
+
| `toClause(kind, number, code, [options])` | the wording for a cheque, invoice, receipt or contract, in Arabic, English or both |
|
|
517
479
|
| `NumberFormat.supportedLocalesOf(locales)` | the locales of a language that is loaded (English with `arqam/en`) |
|
|
518
480
|
|
|
519
481
|
```js
|
|
520
|
-
arqam.utils.count(11, {single: "سيارة", plural: "سيارات", gender: "feminine"});
|
|
521
|
-
|
|
482
|
+
arqam.utils.count(11, {single: "سيارة", plural: "سيارات", gender: "feminine"});
|
|
483
|
+
// إحدى عشرة سيارةً
|
|
484
|
+
arqam.utils.toCase("السادس والعشرون", "jarr"); // السادس والعشرين
|
|
522
485
|
arqam.removeTashkeel("أَلْفٌ وَمِائَتَانِ"); // ألف ومائتان
|
|
523
|
-
arqam.nisba("قطر");
|
|
486
|
+
arqam.nisba("قطر"); // قطري
|
|
524
487
|
```
|
|
525
488
|
|
|
526
489
|
```js
|
|
527
490
|
import {toWords, toParts, createArqam} from "arqam";
|
|
528
491
|
|
|
529
|
-
toWords("11", {ordinal: "f"});
|
|
530
|
-
toWords("21", {ordinal: "m", ordinalDefinite: "off"});
|
|
531
|
-
toWords("1250", {currency: "EGP", wordOrder: "small"});
|
|
532
|
-
|
|
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 سالب)
|
|
533
497
|
|
|
534
498
|
const kw = createArqam({currency: "KWD"});
|
|
535
|
-
kw.toWords("2.5");
|
|
499
|
+
kw.toWords("2.5"); // ديناران كويتيان، وخمسمائة فلس
|
|
536
500
|
```
|
|
537
501
|
|
|
538
|
-
`toWords
|
|
539
|
-
|
|
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])`.
|
|
540
504
|
|
|
541
505
|
</details>
|
|
542
506
|
|
|
@@ -565,10 +529,17 @@ used most:
|
|
|
565
529
|
| `locale` | `"ar"`, `"ar-QA"` … the 22 Arab League locales | the region's currency, month names, digits, separators and time zone |
|
|
566
530
|
| `timeZone`, `zoneName` | an IANA name; city / country / offset / both / off | the time zone of an exact moment, and how it is named |
|
|
567
531
|
|
|
568
|
-
Coded values take a readable name or a short code:
|
|
569
|
-
|
|
570
|
-
`
|
|
571
|
-
|
|
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`.
|
|
572
543
|
|
|
573
544
|
A misspelt option or a bad value throws a `TypeError` that says what is wrong ("did you mean tashkeel?").
|
|
574
545
|
With `strict: "on"`, a number or date that cannot be written throws too, instead of returning `""`.
|
|
@@ -582,14 +553,15 @@ the options; `new` is optional.
|
|
|
582
553
|
|
|
583
554
|
```js
|
|
584
555
|
import {NumberFormat} from "arqam";
|
|
585
|
-
import "arqam/units";
|
|
556
|
+
import "arqam/units"; // only for style "unit"; adds itself to arqam.NumberFormat
|
|
586
557
|
|
|
587
558
|
new NumberFormat("ar-QA", {style: "currency"}).format(1234.5);
|
|
588
559
|
// ألف ومائتان وأربعة وثلاثون ريالًا قطريًا، وخمسون درهمًا (the currency of the locale's country)
|
|
589
|
-
NumberFormat({style: "percent", maximumFractionDigits: 1}).format(0.125);
|
|
560
|
+
NumberFormat({style: "percent", maximumFractionDigits: 1}).format(0.125);
|
|
561
|
+
// اثنا عشر فاصلة خمسة بالمائة
|
|
590
562
|
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);
|
|
563
|
+
NumberFormat({style: "ordinal", ordinal: "feminine"}).format(21); // الحادية والعشرون
|
|
564
|
+
[1, 2, 3].map(NumberFormat({style: "ordinal"}).format); // ["الأول", "الثاني", "الثالث"]
|
|
593
565
|
NumberFormat({style: "currency", currency: "QAR"}).formatRange(1000, 2000);
|
|
594
566
|
// من ألف ريال قطري إلى ألفي ريال قطري
|
|
595
567
|
NumberFormat({style: "date"}).formatRange("2026-11-01", "2026-11-15");
|
|
@@ -617,7 +589,8 @@ times, data, electrical units, pressure, energy, flow, fuel use and more. A unit
|
|
|
617
589
|
(`"kilometer-per-hour"`), its key (`"E04"`) or its Arabic name (`"كيلومتر في الساعة"`).
|
|
618
590
|
|
|
619
591
|
```js
|
|
620
|
-
arqam.NumberFormat({style: "unit", unit: "kilometer-per-hour"}).format(120);
|
|
592
|
+
arqam.NumberFormat({style: "unit", unit: "kilometer-per-hour"}).format(120);
|
|
593
|
+
// مائة وعشرون كيلومترًا في الساعة
|
|
621
594
|
```
|
|
622
595
|
|
|
623
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>
|
|
@@ -637,7 +610,8 @@ airline hubs are named too, and `registerTimeZone()` names any other zone. The z
|
|
|
637
610
|
```js
|
|
638
611
|
arqam.toDateTime("2026-11-24T06:15:00Z", {locale: "ar-SA"});
|
|
639
612
|
// الرابع والعشرون من شهر نوفمبر لعام ألفين وستة وعشرين للميلاد، الساعة التاسعة وخمس عشرة دقيقةً صباحًا بتوقيت مكة المكرمة
|
|
640
|
-
arqam.toTime("2026-11-24T06:15:00Z", {timeZone: "Europe/London"});
|
|
613
|
+
arqam.toTime("2026-11-24T06:15:00Z", {timeZone: "Europe/London"});
|
|
614
|
+
// الساعة السادسة وخمس عشرة دقيقةً صباحًا بتوقيت لندن
|
|
641
615
|
```
|
|
642
616
|
|
|
643
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>
|
|
@@ -648,15 +622,15 @@ When the exact figure is not wanted, or not known, `approx` writes the number as
|
|
|
648
622
|
gender and case:
|
|
649
623
|
|
|
650
624
|
```js
|
|
651
|
-
arqam("2500", "LBP", {approx: "about"});
|
|
652
|
-
arqam("2500", "LBP", {approx: "over"});
|
|
653
|
-
arqam("2500", "LBP", {approx: "under"});
|
|
625
|
+
arqam("2500", "LBP", {approx: "about"}); // قرابة ألفين وخمسمائة ليرة لبنانية
|
|
626
|
+
arqam("2500", "LBP", {approx: "over"}); // ما يزيد على ألفين وخمسمائة ليرة لبنانية
|
|
627
|
+
arqam("2500", "LBP", {approx: "under"}); // أقل من ألفين وخمسمائة ليرة لبنانية
|
|
654
628
|
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"});
|
|
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"}); // مائة ونيف وعشرون درهمًا مغربيًا
|
|
660
634
|
```
|
|
661
635
|
|
|
662
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>
|
|
@@ -677,11 +651,12 @@ a sub-library: it uses the engine's own functions, and importing it brings the e
|
|
|
677
651
|
```js
|
|
678
652
|
import wordsToNumbers, {find, verify} from "arqam/words";
|
|
679
653
|
|
|
680
|
-
wordsToNumbers("لدي ألفان وخمسمائة ريال وخمستاشر كتاب");
|
|
681
|
-
wordsToNumbers("ألف، ومائتان وخمسون ريالًا قطريًا، وخمسون درهمًا", {currency: "code"});
|
|
682
|
-
|
|
683
|
-
verify("ألف
|
|
684
|
-
verify("ألف ريال قطري، وخمسون درهما", "1250.75", {currency: "QAR"}).
|
|
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
|
|
685
660
|
verify("ألف ريال قطري، وخمسون درهما", "1250.75", {currency: "QAR"}).expectedWords;
|
|
686
661
|
// ألف ومائتان وخمسون ريالًا قطريًا، وخمسة وسبعون درهمًا
|
|
687
662
|
```
|
|
@@ -702,7 +677,8 @@ the page.
|
|
|
702
677
|
|
|
703
678
|
```js
|
|
704
679
|
import {explain} from "arqam/explain";
|
|
705
|
-
explain("13", {currency: "SYP"}).words[0].why;
|
|
680
|
+
explain("13", {currency: "SYP"}).words[0].why;
|
|
681
|
+
// الجزء الأول من 13 يخالف المعدود: «ليرة» مؤنث فجاء بلا تاء.
|
|
706
682
|
```
|
|
707
683
|
|
|
708
684
|
|
|
@@ -719,8 +695,10 @@ The figures in brackets are Arabic-Western numbers (0123456789) by default; `ara
|
|
|
719
695
|
Arabic-Western numbers everywhere else; `arabicNumbers` changes it either way:
|
|
720
696
|
|
|
721
697
|
```js
|
|
722
|
-
arqam.toWords("1250.5", "ar-SA", {style: "currency", brackets: "end"});
|
|
723
|
-
|
|
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)
|
|
724
702
|
arqam.toWords("1250.5", "ar-KW", {style: "currency", arabicNumbers: "eastern", brackets: "end"});
|
|
725
703
|
// ألف ومائتان وخمسون دينارًا كويتيًا، وخمسمائة فلس (١٬٢٥٠٫٥٠٠ KWD)
|
|
726
704
|
```
|
|
@@ -755,7 +733,7 @@ The number of decimals of each currency comes from Arqam's one currency table, s
|
|
|
755
733
|
|
|
756
734
|
```js
|
|
757
735
|
import arqam from "arqam";
|
|
758
|
-
import "arqam/en";
|
|
736
|
+
import "arqam/en"; // English: adds itself to arqam, so it needs no name
|
|
759
737
|
|
|
760
738
|
arqam.NumberFormat.supportedLocalesOf(["ar-QA", "en-GB", "fr-FR"]); // ["ar-QA","en-GB"]
|
|
761
739
|
```
|
|
@@ -765,8 +743,10 @@ arqam.NumberFormat.supportedLocalesOf(["ar-QA", "en-GB", "fr-FR"]); // ["ar-QA
|
|
|
765
743
|
Both languages at once, as on a bilingual cheque or contract:
|
|
766
744
|
|
|
767
745
|
```js
|
|
768
|
-
arqam.toBilingual("1250.50", "QAR").ar;
|
|
769
|
-
|
|
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
|
|
770
750
|
arqam.toBilingual("1250.50", "QAR").figure; // 1,250.50 QAR
|
|
771
751
|
```
|
|
772
752
|
|
|
@@ -821,6 +801,33 @@ See [the library's manual](https://arqampro.com/docs/manual.html#s6).
|
|
|
821
801
|
- **Size (gzipped in brackets):** engine 261.4 KB (79.4 KB), words to numbers 107.2 KB (29.5 KB), «اشرح» 120.0 KB
|
|
822
802
|
(30.9 KB), units 59.1 KB (9.8 KB), English 57.4 KB (18.8 KB). Load only what you use.
|
|
823
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
|
+
|
|
824
831
|
## Documentation and online tools
|
|
825
832
|
|
|
826
833
|
| | |
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "arqam",
|
|
3
|
-
"version": "2.0.
|
|
3
|
+
"version": "2.0.1",
|
|
4
4
|
"arqamEngine": "1.90",
|
|
5
5
|
"description": "Arabic number-to-words (tafqeet): amounts in 188 currencies, numbers, ordinals, percentages, units of measure, Gregorian or Hijri dates, times and fractions, with full i'rab and tashkeel; an Intl-style formatter (arqamAR.NumberFormat). Also reads Arabic number words back into numbers, dialects included. No dependencies, no network. 2.x is a new library; the old one is arqam@1.",
|
|
6
6
|
"keywords": [
|
|
@@ -105,7 +105,12 @@
|
|
|
105
105
|
"README.md",
|
|
106
106
|
"LICENSE"
|
|
107
107
|
],
|
|
108
|
-
"sideEffects":
|
|
108
|
+
"sideEffects": [
|
|
109
|
+
"./dist/arqamEN.mjs",
|
|
110
|
+
"./dist/arqamUnits.mjs",
|
|
111
|
+
"./dist/arqamWordsToNumbers.mjs",
|
|
112
|
+
"./dist/arqamExplain.mjs"
|
|
113
|
+
],
|
|
109
114
|
"engines": {
|
|
110
115
|
"node": ">=14.13"
|
|
111
116
|
},
|