arqam 2.0.1 → 2.0.2

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 CHANGED
@@ -1,20 +1,19 @@
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
1
  <p align="center">
5
2
  <img src="https://arqampro.com/images/ArqamLogo_2_128.png" width="96" height="96" alt="Arqam logo">
6
3
  </p>
7
4
 
8
- <h1 align="center">Arqam (أرقام) — numbers in words</h1>
5
+ <h1 align="center">Arqam (أرقام) — Numbers in Words</h1>
9
6
 
10
- <p align="center">(c) 2020-2026 Mohsen Alyafei</p>
7
+ <p align="center">© 2020–2026 Mohsen Alyafei</p>
11
8
 
12
9
  <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
10
+ Currency amounts, numbers (cardinals and ordinals), dates, and times in grammatically correct words — in both <strong>Arabic</strong> and <strong>English</strong>.<br><br>
11
+ The Arabic output includes full <em>i'rab</em> (إعراب) and <em>tashkeel</em> (تشكيل), and Arabic words can be parsed back into numbers.<br><br>
12
+ <em>Tafqeet</em> (تفقيط, also spelled <em>tafqit</em> or <em>tafgeet</em>) in JavaScript: the successor to <code>tafqit</code> and <code>nArabicWords</code>.<br><br>
13
+ Pure JavaScript · Zero dependencies · No network · MIT Licence
16
14
  </p>
17
15
 
16
+
18
17
  <p align="center">
19
18
  <a href="https://arqampro.com"><b>Try it online</b></a> ·
20
19
  <a href="https://arqampro.com/docs/manual.html"><b>Manual</b></a> ·
@@ -36,12 +35,11 @@
36
35
  ## Arabic numbers in words, written the way a grammarian would
37
36
 
38
37
  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.
38
+ Arqam writes them with the correct gender, number and case every time, and is checked against the Golden Book's **350,100 entries** (314,028 number forms and 36,072 currency-amount forms). The successor of tafqit and nArabicWords.
41
39
 
42
40
  | Why Arqam | What you get |
43
41
  |---|---|
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) |
42
+ | **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 350,100 entries (314,028 number forms and 36,072 currency-amount forms) |
45
43
  | **Ready&nbsp;for&nbsp;cheques&nbsp;and&nbsp;invoices** | 188 currencies with their subunits, «فقط … لا غير», the legal wording, and the same amount in English |
46
44
  | **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
45
  | **More&nbsp;than&nbsp;amounts** | Ordinals up to 999,999, Hijri and Gregorian dates, times and fractions |
@@ -49,7 +47,7 @@ Arqam writes them with the correct gender, number and case every time, and is ch
49
47
  | **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
48
  | **Units&nbsp;of&nbsp;measure** | `arqam/units`: 304 units, by their international or Arabic names |
51
49
  | **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) |
50
+ | **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: 350,100 entries (314,028 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
51
  | **Light&nbsp;and&nbsp;private** | Pure JavaScript, no dependencies, nothing sent over the network, TypeScript types, MIT licence |
54
52
 
55
53
  **Try it in ten seconds:**
@@ -118,18 +116,21 @@ Intl's option names, defaults and methods are kept; Arqam's own options sit besi
118
116
  <!-- gen:why -->
119
117
  ## Why Arqam
120
118
 
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".
119
+ Many tools and libraries convert numbers into Arabic words, yet most get the grammar wrong; from the gender polarity of numbers (التذكير والتأنيث) for three (3) through ten (10) to the dual form (المثنى), case endings (الإعراب), and scale words.
120
+
121
+ Arqam (أرقام, meaning "numbers") was built to ensure that every amount on a cheque, invoice, or contract is written in accurate, formal Arabic (التفقيط), completely free for everyone.
124
122
 
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.
123
+ ### Key technical advantages
124
+
125
+ - **Classical Arabic grammar (naḥw and ṣarf)**
126
+ - **Gender and the counted noun:** 1 and 2 agree with the noun, 3 to 10 take the opposite gender, and the compounds 11 to 19 and 21 to 99 follow their own rules.
127
+ - **Case (إعراب):** nominative, accusative and genitive. The dual drops its ن in iḍāfa (ألفا ريال, not ألفان ريال), and the تمييز after 11 to 99 is accusative.
128
+ - **Spelling and marks:** more than 60 options, among them tashkeel from none to full, مائة or مئة, the Arabic (مليار), short (بليون) and long scales, and the cheque form «فقط … لا غير».
129
+ - **188 currencies, exact amounts:** each with its unit and sub-unit, decimal places, gender and plurals. Amounts are read as text or BigInt, so there is no floating-point error, and there is no limit on the size of a number.
130
+ - **More than amounts:** ordinals, approximate quantities (قرابة، ما يزيد على، أقل من، بضعة، نيّف), Hijri and Gregorian dates, times and fractions. Arabic words read back into digits (`arqam/words`), and the إعراب of every word (`arqam/explain`).
131
+ - **No dependencies, runs anywhere:** ES modules for the browser (also straight from jsDelivr), Node, Deno and bundlers; Arabic built in, English as `arqam/en`.
132
+ - **Checked against the Golden Book:** 350,100 entries (314,028 number forms and 36,072 currency-amount forms).
130
133
 
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
134
  <!-- /gen:why -->
134
135
 
135
136
  ## Why not ask an AI model to do the job?
@@ -172,7 +173,7 @@ The modules are minified, each under a banner with its version and licence; the
172
173
 
173
174
  **In a web page, from a CDN.** jsDelivr serves the latest version of the npm package, so fixes and new features
174
175
  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
+ `arqam@2.0.2` in the address.
176
177
 
177
178
  ```html
178
179
  <script type="module">
@@ -211,7 +212,7 @@ For every part, an import map gives the page the same names as npm (`"arqam"`, `
211
212
  ```
212
213
 
213
214
  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
+ to `arqam`, so there is nothing to name. To check the files, give the exact version (`arqam@2.0.2`) and add an
215
216
  `"integrity"` entry to the import map with the hashes in `dist/SRI.txt`.
216
217
 
217
218
  **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/),
@@ -322,7 +323,7 @@ Arabic-Western and Arabic-Eastern numbers are both accepted, with `-` before and
322
323
 
323
324
  ## Recipes
324
325
 
325
- One call for each common task. Every line is run by the README test.
326
+ One call for each common task.
326
327
 
327
328
  ```js
328
329
  import arqam from "arqam";
@@ -370,7 +371,7 @@ https://api.arqampro.com/v1/words?n=1250.50&currency=SAR
370
371
  ```
371
372
 
372
373
  ```json
373
- { "input": "1250.50", "words": "ألف ومائتان وخمسون ريالًا سعوديًا، وخمسون هللةً", "version": "1.90" }
374
+ { "input": "1250.50", "words": "ألف ومائتان وخمسون ريالًا سعوديًا، وخمسون هللةً", "version": "1.93" }
374
375
  ```
375
376
 
376
377
  `version` is the Arabic engine's version (`arqamEngine` in `package.json`), not the npm package's.
@@ -382,7 +383,8 @@ https://api.arqampro.com/v1/words?n=1250.50&currency=SAR
382
383
  | `/v1/english?n=…` | a number or amount in English words |
383
384
  | `/v1/date?d=23/11/2026` | a date in words (`calendar=g`, `h` or `b`) |
384
385
  | `/v1/time?t=15:45` | a time in words |
385
- | `/v1/value?text=…` | Arabic words back to their number |
386
+ | `/v1/fraction?f=3%2F4` | a fraction in words (`fractionForm`, `fractionOf=…` for «ثلثا المبلغ») |
387
+ | `/v1/value?text=…` | Arabic words back to their number (`fractions=on`: «ثلاثة أرباع» → `3/4`) |
386
388
  | `/v1/explain?n=…` | the إعراب of each word |
387
389
 
388
390
  The options are the library's own (`currency`, `tashkeel`, `ierab`, `legal`, `wordOrder` …); `format=text` gives the
@@ -643,6 +645,33 @@ arqam("125", "MAD", {approx: "plus"}); // مائة ونيف وعشرون در
643
645
 
644
646
  A number that neither fits gives `""`; with `strict: "on"` it throws a `RangeError`.
645
647
 
648
+ ## Fractions
649
+
650
+ A fraction is written as you type it: `3/4`, `3 1/2`, `3½`, `-3/4`. Halves to tenths are named (ثلث، ربع … عشر, with a
651
+ damma on the second letter in full tashkeel); above tenths a fraction is «أجزاء من». A value of one or more is a mixed
652
+ number unless `fractionMixed: "off"`.
653
+
654
+ ```js
655
+ arqam("3/4"); // ثلاثة أرباع
656
+ arqam("3½"); // ثلاثة ونصف
657
+ arqam("-3/4"); // سالب ثلاثة أرباع
658
+ arqam.toFraction("7/16"); // سبعة أجزاء من ستة عشر
659
+ arqam.toFraction("5/3", {fractionMixed: "off"}); // خمسة أثلاث
660
+ arqam.toFraction("3/4", {fractionForm: "math"}); // ثلاثة على أربعة
661
+ ```
662
+
663
+ A fraction of a noun (`fractionOf`): the fraction takes the case you ask for and your words follow it exactly as you give
664
+ them. With a currency the exact amount is written in the small unit, or the fraction is named with `fractionUnit: "named"`:
665
+
666
+ ```js
667
+ arqam.toFraction("2/3", {fractionOf: "المبلغ", ierab: "nasb"}); // ثلثي المبلغ
668
+ arqam.toFraction("2/3", {fractionOf: "الْمَبْلَغِ", ierab: "nasb", tashkeel: "full"}); // ثُلُثَيِ الْمَبْلَغِ
669
+ arqam.toFraction("3/4", {currency: "QAR"}); // خمسة وسبعون درهمًا قطريًا
670
+ arqam.toFraction("3/4", {currency: "QAR", fractionUnit: "named"}); // ثلاثة أرباع ريال قطري
671
+ ```
672
+
673
+ The fraction words in every form, case and tashkeel level are in the [golden book](https://github.com/MohsenAlyafei/arqam/blob/master/golden/README.md)'s fraction files.
674
+
646
675
  ## Words back to numbers
647
676
 
648
677
  `arqam/words` reads Arabic number words in any text (dialects too), with fractions, currencies and a cheque check. It is
@@ -652,6 +681,8 @@ a sub-library: it uses the engine's own functions, and importing it brings the e
652
681
  import wordsToNumbers, {find, verify} from "arqam/words";
653
682
 
654
683
  wordsToNumbers("لدي ألفان وخمسمائة ريال وخمستاشر كتاب"); // لدي 2500 ريال و15 كتاب
684
+ wordsToNumbers("دفعت ثلاثة أرباع المبلغ"); // دفعت 3/4 المبلغ
685
+ wordsToNumbers("سبعة أجزاء من ستة عشر", {fractions: "on"}); // 7/16
655
686
  wordsToNumbers("ألف، ومائتان وخمسون ريالًا قطريًا، وخمسون درهمًا", {currency: "code"});
656
687
  // 1250.50 QAR
657
688
  verify("فقط ألف ومائتان وخمسون ريالًا قطريًا لا غير", "1250", {currency: "QAR"}).ok; // true
@@ -882,9 +913,9 @@ engine as the npm package, with a code editor beside it:
882
913
  | [`ar/`](https://github.com/MohsenAlyafei/arqam/blob/master/ar/) | the README of the Arabic engine `arqamAR` (its code is in `src/`) |
883
914
  | [`en/`](https://github.com/MohsenAlyafei/arqam/blob/master/en/) | the English engine `arqamEN`, and its README |
884
915
  | [`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` |
916
+ | [`tests/`](https://github.com/MohsenAlyafei/arqam/blob/master/tests/) | the library's tests: `npm test` |
886
917
  | [`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) |
918
+ | [`js/`](https://github.com/MohsenAlyafei/arqam/blob/master/js/) | the currency and unit tables the units add-on is built from (shared with the page) |
888
919
  | [`docs/`](https://github.com/MohsenAlyafei/arqam/blob/master/docs/) | `DEVELOPER.md` |
889
920
 
890
921
  The Arqam page, manual and playground are published on [arqampro.com](https://arqampro.com).
package/dist/SRI.txt CHANGED
@@ -1,5 +1,5 @@
1
- sha384-EIzWC94ZAbLzcF+CeZCqwpsLnIwXp0Mu5IQduzkXhl4Rej+QI2uzvNdAW8UMWoBK arqamAR.mjs
1
+ sha384-Kr9McehfxLWFyfOZh0J02la+gxEb0OLwaGkI4XLoaysSqtqhZvNYvtZrFm6erFon arqamAR.mjs
2
2
  sha384-ocjkJMUCeSQQaTmNy55NhEMwyJ9ktFWm/IUXCef4zzNKJbVuEXKR7DB1KwaLZxMY arqamEN.mjs
3
- sha384-l/DvoIhl9cFY1flX4MuXfneZHj8mTP+wFWqa6Z9YeITc7KUuR9dp9eTyFzdbRngx arqamWordsToNumbers.mjs
4
- sha384-qHnvei9vHKkTU2lBOpOwMuDGJyWYW9GNH/3qGS8uGfHh1OAnDSLi7wFbQXOurvIt arqamExplain.mjs
5
- sha384-AX89Ahf+VwLyBc5nKAGgHVpObkMtIHQfubde/TU4i/O3Q/gsDK9uHWzLH8NcSTB8 arqamUnits.mjs
3
+ sha384-e+zT7styCVo+tty4Yqc23H1N4Sop+zCXumQa9oXSeNX+GBP9g+1K34jmKDtgsASh arqamWordsToNumbers.mjs
4
+ sha384-luWRJ6Sa3HfnKba7WTvFaB7Cl1iaL8jm2tdO661D6FM3A1sGG+yjTYPMjMduaBSd arqamExplain.mjs
5
+ sha384-oWyOiFo5zCpf7GffTRa5+XA8V8FHWNIvn9qCgdo4GJZZXv1nsFf7lXTx+yqq9bKK arqamUnits.mjs
@@ -1,8 +1,9 @@
1
- /*! arqamAR — TypeScript declarations for dist/arqamAR.mjs. MIT licence.
2
- * Copied to dist/ by tools/build_dist.py; tests/dist.test.js checks that every option, currency attribute
3
- * and export of the engine is declared here.
4
- * @author: Mohsen Alyafei */
5
-
1
+ /*********************************************************************
2
+ * @file : arqamAR.d.mts
3
+ * @purpose : TypeScript declarations for arqamAR.mjs: every option, currency attribute and export.
4
+ * @author : Mohsen Alyafei
5
+ * @Licence : MIT
6
+ **********************************************************************/
6
7
  /** A number: text ("1234.56", Arabic-Eastern numbers too, "-" before and "%" after allowed), a JS number or a BigInt.
7
8
  * Pass amounts as text: a JS number keeps only about 16 significant digits. */
8
9
  export type ArqamNumber = string | number | bigint;
@@ -317,6 +318,13 @@ export interface ArqamFractionOptions {
317
318
  /** With a code: minor (default): the minor unit when the amount is exact (2 1/2 QAR -> ريالان قطريان اثنان، وخمسون درهمًا) ·
318
319
  * named: the fraction word (ريالان قطريان اثنان ونصف، نصف ريال قطري) */
319
320
  fractionUnit?: "" | "minor" | "named";
321
+ /** A fraction of a noun: the phrase (المضاف إليه) the fraction is a share of, joined exactly as given; the fraction is
322
+ * the first term in the case of ierab: ثلثُ المبلغِ، ثلثَيِ المبلغِ، سبعةُ أجزاءٍ من ستةَ عشرَ منَ المبلغِ. Only a
323
+ * fraction more than zero and less than one; not with a currency or fractionForm "math" */
324
+ fractionOf?: string;
325
+ /** The second letter of the fraction words: "classical" (default) a damma throughout: ثُلُث، رُبُع، خُمُس … عُشُر;
326
+ * "modern" a sukun after ثُلُث: رُبْع، خُمْس … عُشْر. Only full tashkeel shows it */
327
+ fractionVowels?: "" | "classical" | "modern";
320
328
  /** Shared with the number options */
321
329
  tashkeel?: ArqamOptions["tashkeel"];
322
330
  tanweenAlif?: ArqamSwitch;
@@ -562,8 +570,8 @@ export interface ArqamUtils {
562
570
  parseDate(text: ArqamDate, options?: {input?: "g" | "h" | "gregorian" | "hijri"; order?: "dmy" | "mdy"}): ArqamDay & {hijri: ArqamDay | null; date: Date};
563
571
  /** A time of day, or a duration */
564
572
  parseTime(text: ArqamTime, options?: {duration?: boolean}): {hour: number; minute: number; second: number};
565
- /** A typed fraction: "3 1/2", "¾", "2.5" */
566
- parseFraction(text: ArqamFraction): {whole: string; numerator: number; denominator: number};
573
+ /** A typed fraction: "3 1/2", "¾", "2.5"; a fraction below zero ("-3/4") also has negative: true */
574
+ parseFraction(text: ArqamFraction): {whole: string; numerator: number; denominator: number; negative?: true};
567
575
  /** The Hijri (Umm al-Qura) day of a date */
568
576
  hijri(date: Date | string): ArqamDay;
569
577
  /** The Gregorian day of a Hijri date (a RangeError if that day does not exist) */
@@ -606,7 +614,7 @@ export interface ArqamLibraryNumberFormat {
606
614
  /** The library, shaped as Intl: the locale chooses the language (Arabic by default); the other methods are Arabic. */
607
615
  export interface ArqamLibrary extends Omit<Arqam, "NumberFormat" | "toWords"> {
608
616
  /** arqam(n, locales, options) is arqam.toWords(n, locales, options); a currency code in place of the locales is the
609
- * short form of an amount (engine 1.86): arqam("1250.50", "EGP") is arqam("1250.50", {currency: "EGP"}) */
617
+ * short form of an amount: arqam("1250.50", "EGP") is arqam("1250.50", {currency: "EGP"}) */
610
618
  (n: ArqamNumber, locales?: string | string[], options?: ArqamNumberFormatOptions | import("./arqamEN.mjs").ArqamENNumberFormatOptions): string;
611
619
  (n: ArqamNumber, options?: ArqamNumberFormatOptions): string;
612
620
  /** Every language, chosen by the locale */