Skip to content
BesrourMSPublic

Latest commit

 

History

2 Commits

Folders and files

NameName
Last commit message
Last commit date
 
 
 
 
 
 

Repository files navigation

Abjad — Hisab al-Jumal calculator & reader

A dependency-free JavaScript library and interactive web reader for حساب الجُمَّل (Hisab al-Jumal) — the classical system that assigns each letter of the Arabic alphabet a numeric value, in the traditional mnemonic order أبجد هوز حطي كلمن سعفص قرشت ثخذ ضظغ. Historically used for chronograms, numerology (ʿilm al-jafr), and mnemonic ordering, and still used today for name/word numerology.

Features

  • Abjad class — get the total value of a string, a letter-by-letter breakdown, or the single-digit "reduced" root (abjad saghir) of a total
  • Interactive reader (abjad-reader.html) — a standalone, RTL, manuscript-styled page that annotates each letter's value live as you type, with a running ledger and toggleable conventions for shadda and taa marbuta
  • Zero dependencies, no build step — plain JavaScript and a single self-contained HTML file
  • Handles modern Arabic text gracefully: hamza forms (ء ؤ ئ) and alif/ya variants (أ إ آ ٱ, ى) map to their carrier letter's value instead of being silently dropped

Quick start

Interactive reader

Open abjad-reader.html directly in any browser — no server or build step needed. Type or paste Arabic text and watch each letter's value get annotated live, a running ledger fill in, and the total (kabir) and its digital root (saghir) update as you go. Three quick-fill chips (محمد، الله، بسم الله الرحمن الرحيم) are included for trying it out immediately.

Using the library

This repo doesn't currently ship an npm package — index.js defines a plain global Abjad class rather than an ES module or CommonJS export. Drop it into a page with a script tag:

<script src="index.js"></script>
<script>
  console.log(Abjad.calculate('محمد'));   // 92
  console.log(Abjad.breakdown('محمد'));
  // [ { letter: 'م', value: 40 }, { letter: 'ح', value: 8 },
  //   { letter: 'م', value: 40 }, { letter: 'د', value: 4 } ]
  console.log(Abjad.reduce(92));          // 2  (9 + 2 = 11 → 1 + 1 = 2)
</script>

To use it in Node.js, add module.exports = Abjad; to the end of index.js first — it isn't there by default.

API (index.js)

Abjad.calculate(text)

Returns the total abjad value of text as a number. Unrecognized characters (spaces, punctuation, Latin script, etc.) contribute 0.

Abjad.breakdown(text)

Returns an array of { letter, value } for every recognized letter in text, in order. Unmapped characters are skipped entirely rather than listed as zero-value entries.

Abjad.reduce(value)

Returns the digital root of a non-negative integer — repeatedly sums its digits until a single digit (0–9) remains. This is the abjad-saghir ("small") value corresponding to a kabir ("large") total.

Note: the exported index.js class doesn't currently take a shadda or taa-marbuta option — calculate and breakdown always use the classical, unmodified letter values below. The extended engine with those options lives only in the reader (see next section).

Letter values

The 28 classical letters, in abjad order:

ا ب ج د ه و ز ح ط ي
1 2 3 4 5 6 7 8 9 10
ك ل م ن س ع ف ص
20 30 40 50 60 70 80 90
ق ر ش ت ث خ ذ
100 200 300 400 500 600 700
ض ظ غ
800 900 1000

Variant forms share their base letter's value: أ, إ, آ, ٱ → 1 (ا); ى → 10 (ي); ة → 5 (ه). Hamza forms ؤ, ئ, ء aren't part of the classical 28-letter set but are mapped here to their carrier consonant (و=6, ي=10, ا=1) so ordinary modern text — which uses them constantly — isn't undercounted.

The reader (abjad-reader.html)

This page is fully self-contained — it does not load index.js; it embeds its own, more capable copy of the Abjad class. It adds:

  • Live per-letter value annotation as you type, styled after manuscript rubrication (values marked in red above the text)
  • A running ledger table (letter → value → running total)
  • Kabir total and its reduced saghir digit, both rendered in Arabic-Indic numerals
  • A reference strip of the full alphabet in its traditional mnemonic groupings
  • Two toggles that the plain index.js class doesn't expose:
    • الشدّة تُحسب مرتين (double for shadda) — doubles a letter's value when it carries a shadda (ّ)
    • ة = ت (٤٠٠) (taa marbuta as taa) — values ة as 400 (like ت) instead of the default 5 (like ه)

Project structure

.
├── index.js            # Abjad class: calculate / breakdown / reduce (no options)
├── abjad-reader.html   # standalone interactive reader (self-contained, own Abjad copy)
└── README.md

Known limitation

index.js and the Abjad class embedded in abjad-reader.html have diverged: the reader's copy supports the shadda and taa-marbuta options through an internal tokenize / effectiveValue pipeline that index.js doesn't have. A fix or new rule added to one won't apply to the other unless it's ported by hand. Unifying them into one shared module — and adding a package.json so index.js can be require'd or import'd normally — would be a natural next step.

Contributing

Issues and pull requests are welcome — this is a small, single-file project, so most changes are easy to review.