DEV Community

Cover image for I Built a Free, Dependency-Free Gematria Calculator with Vanilla JS
Waqar Taqi
Waqar Taqi

Posted on

I Built a Free, Dependency-Free Gematria Calculator with Vanilla JS

What is Gematria?

Gematria is the ancient practice of assigning numerical values to letters — used for centuries to uncover hidden meanings and connections between words. Every Hebrew letter carries a number (Aleph = 1, Bet = 2 ... Tav = 400), and similar systems exist for English (A=1, B=2...Z=26), Greek, and more.

I wanted a calculator that was fast, free, and didn't need a sign-up or a build step — so I built one with plain HTML, CSS, and JavaScript. No frameworks, no dependencies, no bundler.

Live site: gematriacalculators.net
Source code: GitHub repo

The Core Idea

At its simplest, gematria is just a character-to-number lookup, summed across a string. Here's the "Simple English" cipher:

function calcSimple(text) {
  text = text.toUpperCase().replace(/[^A-Z]/g, '');
  let total = 0;
  for (let i = 0; i < text.length; i++) {
    total += text.charCodeAt(i) - 64; // A=1, B=2 ... Z=26
  }
  return total;
}
Enter fullscreen mode Exit fullscreen mode

From there, other ciphers are just different lookup tables. Jewish gematria, for example, uses non-sequential values:

const JEW = {
  A:1, B:2, C:3, D:4, E:5, F:6, G:7, H:8, I:9, J:600,
  K:10, L:20, M:30, N:40, O:50, P:60, Q:70, R:80, S:90,
  T:100, U:200, V:700, W:900, X:300, Y:400, Z:500
};

function calcMap(text, MAP) {
  text = text.toUpperCase().replace(/[^A-Z]/g, '');
  let total = 0;
  for (let i = 0; i < text.length; i++) {
    total += MAP[text[i]] || 0;
  }
  return total;
}
Enter fullscreen mode Exit fullscreen mode

Handling Hebrew

The trickiest part was Hebrew, since it needs its own character map (not derived from character codes) and has "sofit" (final-form) letters — five Hebrew letters change shape when they appear at the end of a word, and traditionally share the same gematria value as their standard form:

const HEB_MAP_STANDARD = {
  'א':1, 'ב':2, 'ג':3, 'ד':4, 'ה':5, 'ו':6, 'ז':7, 'ח':8, 'ט':9,
  'י':10, 'כ':20, 'ל':30, 'מ':40, 'נ':50, 'ס':60, 'ע':70,
  'פ':80, 'צ':90, 'ק':100, 'ר':200, 'ש':300, 'ת':400,
  // sofit (final) forms map back to their base letter's value
  'ך':20, 'ם':40, 'ן':50, 'ף':80, 'ץ':90
};
Enter fullscreen mode Exit fullscreen mode

One classic example: שלום (Shalom, "peace") = 300 + 30 + 6 + 40 = 376.

Greek Isopsephy

Greek isopsephy adds another wrinkle — some values are assigned to digraphs (two-letter combinations like TH, PH, CH, PS) rather than single letters, so the parser has to greedily check two-character lookaheads before falling back to single characters:

function calcGreekIso(text) {
  text = text.toUpperCase().replace(/[^A-Z]/g, '');
  let total = 0, i = 0;
  while (i < text.length) {
    if (i + 1 < text.length) {
      const digraph = text[i] + text[i+1];
      if (['TH','PH','CH','PS'].includes(digraph)) {
        total += GREEK_TRANSLIT[digraph];
        i += 2;
        continue;
      }
    }
    total += GREEK_TRANSLIT[text[i]] || 0;
    i++;
  }
  return total;
}
Enter fullscreen mode Exit fullscreen mode

Why No Framework?

Honestly — it didn't need one. The whole calculator is a text input, a cipher selector, and a results display. Adding React or a build pipeline would've meant more tooling for zero functional benefit. The entire thing is a single HTML file you can open directly in a browser or drop into any static host.

Try It / Fork It

If you spot a cipher system I'm missing, or want to add one, PRs are welcome. Would also love feedback from anyone who's worked with Hebrew or RTL text rendering — happy to compare notes in the comments 👇

Top comments (0)