↑ Top
GitHubArqam

Manual: the library

Manual: the library

Arqam writes numbers, amounts, dates and documents in words, in Arabic and English. This manual is the library's: the names, loading it, the calls that join languages and documents. Each language has its own manual: Arabic (arqamAR), English (arqamEN).

1. One library, many languages

arqam is the library. Each language is an engine of its own, named arqam with the language's two-letter ISO 639-1 code in capitals, reached through arqam by its locale, as in Intl. Arabic is the default: arqam(n, locales, options) and new arqam.NumberFormat(locales, options) take Intl's shape, and the other calls of arqam are Arabic.

CodeLanguageEngineModuleLocalesManualREADME
arArabicarqamARbuilt inar, ar-QA, ar-SA … (the default)arqamAR-manual.htmlar/README.md
enEnglisharqamENarqam/enen-US, en-GB, en-IN …arqamEN-manual.htmlen/README.md

What joins the languages lives in the library only, never in one language engine: toBilingual(), toLanguages() and toClause(). The amount, its decimals, its figure and the dates come from Arqam's one currency table and calendar, so every language writes the same amount and the same day.

2. The names

Every language engine is arqam + its code in capitals: arqamAR, arqamEN, and later arqamFR, arqamDE … They are the names of the files to load; the calls go through arqam, and the locale chooses the language, as in Intl. arqam.NumberFormat.supportedLocalesOf(locales) gives the locales of the languages loaded.

arqam("1250.50", "ar-QA", {style: "currency"})
→ألف ومائتان وخمسون ريالًا قطريًا، وخمسون درهمًا
arqam("1250.50", "en-GB", {currency: "QAR"})
→One Thousand Two Hundred and Fifty Qatari Riyals and Fifty Dirhams
arqam.NumberFormat.supportedLocalesOf(["ar", "en", "fr"])
→aren
arqam("5", {currency: "QAR"})
→خمسة ريالات قطرية

A language engine loaded on its own puts itself in one shared table, keyed by Symbol.for("arqam.languages"), so the library finds it however the files were loaded (plain scripts in any order, or ES modules). The table adds no global name.

One NumberFormat for every language

As JavaScript's one Intl.NumberFormat, the library's arqam.NumberFormat chooses the language from the locale: the first locale of the list whose language is loaded decides, and the call goes to that language's engine, with its options and checks. arqam(n, locales, options) gives the words of its format(n), as n.toLocaleString(locales, options); the rounding is Intl's (3 places for a number, the currency's minor unit, a whole percentage, half up). With no locale it is Arabic, as arqam is. A language that is not loaded, or that Arqam does not write, is a RangeError that says so.

new arqam.NumberFormat("ar-QA", {currency: "QAR"}).format(1250.5)
→ألف ومائتان وخمسون ريالًا قطريًا، وخمسون درهمًا
new arqam.NumberFormat("en-GB", {currency: "QAR"}).format(1250.5)
→One Thousand Two Hundred and Fifty Qatari Riyals and Fifty Dirhams
new arqam.NumberFormat("en-IN", {currency: "INR"}).format(123456)
→One Lakh Twenty-Three Thousand Four Hundred and Fifty-Six Indian Rupees
new arqam.NumberFormat({currency: "QAR"}).format(5)
→خمسة ريالات قطرية
new arqam.NumberFormat(["fr-FR", "en-GB", "ar-QA"]).format(21)
→"Twenty-One"
arqam.NumberFormat.supportedLocalesOf(["ar-QA", "en-GB", "fr-FR"])
→ar-QAen-GB
new arqam.NumberFormat("fr-FR")
→RangeError: arqam.NumberFormat: Arqam writes ar, en (got "fr-FR")

3. Install and load

npm install arqam
import arqam from "arqam";            // the library: Arabic by default
import "arqam/en";                    // English, by its locale (en-GB, en-US …)
import arqamWordsToNumbers from "arqam/words";   // Arabic words back to numbers
import arqamExplain from "arqam/explain";        // «اشرح»: the grammar of every word
import arqamUnits from "arqam/units";            // 252 units of measure

As plain scripts (no build step), in this order: the Arabic engine first, then what you need. arqamAR.js gives the two names arqam and arqamAR; arqamEN.js adds English to the library.

<script src="src/arqamAR.js"></script>
<script src="en/arqamEN.js"></script>
<script>
  document.title = arqam("1250.50", "ar-QA", {style: "currency"}) + " · " + arqam("1250.50", "en-GB", {currency: "QAR"});
</script>
ModuleWhat it is
arqamthe library (default export) and the Arabic engine (named export arqamAR)
arqam/enthe English engine, arqamEN
arqam/wordsArabic words back to numbers (fromWords, findNumbers, verify)
arqam/explainthe grammar of the Arabic words
arqam/unitsunits of measure for NumberFormat

4. Two languages at once

toBilingual(number, code [, options]) gives {ar, en, figure}: the Arabic with «فقط … لا غير» and the tanween on the alif, as written on cheques; the English in UK style with "Only" at the end. toLanguages(number, code, languages [, options]) does the same for any languages loaded.

arqam.toBilingual("1250.50", "QAR").ar
→فقط ألف ومائتان وخمسون ريالًا قطريًا، وخمسون درهمًا لا غير
arqam.toBilingual("1250.50", "QAR").en
→One Thousand Two Hundred and Fifty Qatari Riyals and Fifty Dirhams Only
arqam.toBilingual("1250.50", "QAR").figure
→1,250.50 QAR
OptionValuesMeaning
only"off"leave out «فقط … لا غير» and "Only"
onlyEn"end" "start"where "Only" goes in English (default end)
tashkeelas toWordsthe Arabic's tashkeel (default "a": the alif)
style"uk" "us"the English: uk (default) writes "and" before the tens and units
arqam.toBilingual("1250.50", "QAR", {style: "us", onlyEn: "start"}).en
→Only One Thousand Two Hundred Fifty Qatari Riyals and Fifty Dirhams
arqam.toBilingual("1250.50", "QAR", {only: "off", tashkeel: "full"}).ar
→أَلْفٌ وَمِائَتَانِ وَخَمْسُونَ رِيَالًا قَطَرِيًّا، وَخَمْسُونَ دِرْهَمًا
JSON.stringify(arqam.toLanguages("99.5", "KWD", ["en", "ar"]))
→{"en":"Ninety-Nine Kuwaiti Dinars and Five Hundred Fils Only","ar":"فقط تسعة وتسعون دينارًا كويتيًا، وخمسمائة فلس لا غير","figure":"99.500 KWD"}

5. Documents: cheques, invoices, receipts, contracts

toClause(kind, number, code [, options]) writes the wording of a document around the amount: "cheque", "invoice", "receipt" or "contract" (a contract article). It gives {text, lines, words, figure}; lang: "en" writes it in English, lang: ["ar", "en"] in both ({ar, en, text}). The wording is Arqam's own, the same as the «مستندات» mode of the Arqam page; it does not claim to follow any bank's or regulator's form.

arqam.toClause("cheque", "15400.75", "QAR", {payee: "شركة الخليج للتجارة", date: "2026-11-27"}).text
→ادفعوا لأمر: شركة الخليج للتجارة مبلغًا وقدره: فقط خمسة عشر ألفًا وأربعمائة ريال قطري، وخمسة وسبعون درهمًا لا غير (15,400.75 QAR) التاريخ: 27 نوفمبر 2026م
arqam.toClause("cheque", "15400.75", "QAR", {payee: "Gulf Trading Co.", date: "2026-11-27", lang: "en"}).text
→Pay to the order of: Gulf Trading Co. The sum of: Fifteen Thousand Four Hundred Qatari Riyals and Seventy-Five Dirhams Only (QAR 15,400.75) Date: 27 November 2026
OptionMeaning
payeewho is paid (or the customer, or who paid)
forwhat the amount is for
refthe cheque, invoice or receipt number
dateISO text or a Date; written in each language
hijrithe Hijri date beside it (the engine's Umm al-Qura calendar, the same day in every language)
clausethe article number of a contract (default 1)
only«فقط … لا غير» and "Only": on, but off in a contract, where the amount sits inside a sentence
tashkeel, style, onlyEnas for toBilingual
lang"ar" (default), "en", or ["ar", "en"]
arqam.toClause("contract", "250000", "SAR", {payee: "Al Noor Est.", for: "the supply works", clause: 5, lang: "en"}).text
→Article 5: Contract Value The Parties agree that the total value of this Contract is Two Hundred and Fifty Thousand Saudi Riyals (SAR 250,000.00), payable by the First Party to the Second Party (Al Noor Est.) in consideration of the supply works, in accordance with the provisions of this Contract.
arqam.toClause("receipt", "750", "AED", {payee: "علي حسن", for: "إيجار شهر نوفمبر", date: "2026-11-27", hijri: true}).text
→سند قبض التاريخ: 27 نوفمبر 2026م، الموافق 17 جمادى الآخرة 1448هـ استلمنا من السيد/السادة: علي حسن مبلغًا وقدره: فقط سبعمائة وخمسون درهمًا إماراتيًا لا غير (750.00 AED) وذلك عن: إيجار شهر نوفمبر
arqam.toClause("invoice", "99.5", "KWD", {payee: "X", lang: ["ar", "en"]}).text
→فاتورة العميل: X البيان: ……………… — 99.500 KWD الإجمالي: 99.500 KWD المبلغ بالحروف: فقط تسعة وتسعون دينارًا كويتيًا، وخمسمائة فلس لا غير Invoice Customer: X Description: ……………… — KWD 99.500 Total: KWD 99.500 Amount in words: Ninety-Nine Kuwaiti Dinars and Five Hundred Fils Only

The wording is one table, arqam.toClause.wording, by language and document; arqam.toClause.kinds lists the documents. The page's «مستندات» reads its Arabic from the same table.

arqam.toClause.kinds
→chequeinvoicereceiptcontract
arqam.toClause.wording.en.cheque.payee + " · " + arqam.toClause.wording.ar.cheque.payee
→Pay to the order of · ادفعوا لأمر

6. Speed

The time grows in step with the length of the number: on the machine of the measurement, a number of 100 digits takes about 0.2 ms in Arabic and under 0.05 ms in English, and one of 1,000,000 digits (about 20 to 34 million characters of words) between 0.7 and 1.6 seconds in Arabic and 0.25 to 0.3 seconds in English. Every size, tashkeel and style, with the sizes of the words: the benchmark.

To measure your own machine, in the Arqam folder from GitHub: node tools/benchmark.js (every size up to 1,000,000 digits, a few minutes) or node tools/benchmark.js --quick (up to 100,000 digits). It prints the table and writes it as a page, arqam-benchmark.html, with the machine it ran on.

node tools/benchmark.js --quick
node tools/benchmark.js --sizes 10,100,1000 --rounds 5 --warmup 3 --out my-benchmark.html
npm run benchmark

7. Adding a language

A new language (French, German …) is a new engine and its documents; the library's code does not change.

  1. The engine, arqamXX.js (XX the ISO 639-1 code in capitals), usable on its own, that gives toWords(number, {mode: "currency", currency: code, style, only}) for an amount (the words of the currency's major and minor units, the decimals of Arqam's currency table), and puts itself in the table: globalThis[Symbol.for("arqam.languages")].xx = arqamXX.
  2. Its README, xx/README.md, and its manual, docs/arqamXX-manual.html (a page of tools/build_lang_manuals.js), and one line for the manual in tools/site_header.js and in the table of languages above.
  3. Its documents (if it writes them): its wording in toClause's table, with the dates in that language.
  4. Its tests, and its module in package.json (arqam/xx).

Then arqam(n, "xx-YY") and new arqam.NumberFormat("xx-YY") (the engine's NumberFormat), toLanguages(n, code, ["ar", "xx"]) and toClause(…, {lang: "xx"}) work with it.

8. Questions

All questions (13)

Q1Is it arqam or arqamAR?Beginner

arqam is the library; arqamAR is the name of its Arabic engine's file. Write arqam: its toWords and NumberFormat take Intl's shape, and its other calls are Arabic.

Object.getPrototypeOf(arqam) === arqamAR
→true
Q2Why are the engines called arqamAR and arqamEN?Beginner

Each language is an engine named arqam with the language's two-letter ISO 639-1 code in capitals: arqamAR, arqamEN, later arqamFR … They name the files to load; the library reaches each language by its locale.

Q3How do I get English words through arqam?Beginner

Load the English engine (arqam/en as a module, or arqamEN.js as a plain script) and give an English locale. Before it is loaded an English locale is a RangeError that says so.

arqam("1250.50", "en-US", {currency: "QAR"})
→One Thousand Two Hundred Fifty Qatari Riyals and Fifty Dirhams
Q4Does loading English add a global name?Intermediate

No: a language engine puts itself in one shared table keyed by Symbol.for("arqam.languages"); a symbol key is not a global name. As plain scripts, arqamAR.js gives arqam and arqamAR, and arqamEN.js gives arqamEN.

Q5How do I write an amount in Arabic and English, as on a bilingual cheque?Beginner

arqam.toBilingual(number, code): the Arabic with «فقط … لا غير», the English with "Only", and the figure.

arqam.toBilingual("2500", "KWD").en
→Two Thousand Five Hundred Kuwaiti Dinars Only
Q6toBilingual or toLanguages?Intermediate

The same thing: toBilingual(n, code) is toLanguages(n, code, ["ar", "en"]). Use toLanguages for another set or order of languages; it gives one entry per language and the figure.

Object.keys(arqam.toLanguages("5", "QAR", ["en", "ar"])).join(", ")
→en, ar, figure
Q7Why is the English in UK style by default here, when arqamEN alone is in US style?Intermediate

Cheques and contracts in the Gulf and the UK write "and" before the tens and units (One Thousand Two Hundred and Fifty). style: "us" gives the US form. arqamEN on its own keeps its own default, US.

arqam.toBilingual("1250", "USD", {style: "us"}).en
→One Thousand Two Hundred Fifty US Dollars Only
Q8Can Arqam write the line of a cheque, an invoice, a receipt or a contract?Beginner

Yes: toClause(kind, number, code, options), in Arabic, English or both.

arqam.toClause("cheque", "2500", "KWD", {payee: "Al Noor Est.", lang: "en"}).lines[1]
→The sum of: Two Thousand Five Hundred Kuwaiti Dinars Only (KWD 2,500.000)
Q9How do I get a document in both languages?Intermediate

lang: ["ar", "en"]: {ar, en, text}, where text is the Arabic, a blank line, then the English.

arqam.toClause("cheque", "100", "QAR", {payee: "X", lang: ["ar", "en"]}).en.lines[1]
→The sum of: One Hundred Qatari Riyals Only (QAR 100.00)
Q10Why has a contract no «فقط … لا غير»?Intermediate

In a contract the amount sits inside a sentence («… مبلغًا وقدره …، يدفعها …»), where «فقط … لا غير» does not belong; only: "on" adds them.

arqam.toClause("contract", "100", "QAR", {only: "on"}).lines[1]
→اتفق الطرفان على أن تكون القيمة الإجمالية لهذا العقد مبلغًا وقدره فقط مائة ريال قطري لا غير (100.00 QAR)، يدفعها الطرف الأول إلى الطرف الثاني (………………)، وفقًا لأحكام هذا العقد.
Q11Can I change the wording of a document?Advanced

The wording is Arqam's own, in arqam.toClause.wording (a copy: changing it changes nothing). For your own form, take words and figure from the result and write your own sentence around them.

[arqam.toClause("cheque", "15", "QAR")].map(r => "Pay " + r.figure)[0]
→Pay 15.00 QAR
Q12What happens if a language is not loaded?Advanced

A TypeError that says what to load.

arqam.toLanguages("5", "QAR", ["fr"])
→TypeError: arqam: the language "fr" is not loaded
Q13How do I add a language?Advanced

An engine, its README and manual, one line in the site's menu and the table of languages, and its document wording if it writes documents: see «Adding a language».