← Blog

Numerology calculator in JavaScript: write it yourself or call an API?

·3 min read

A numerology calculator looks like a weekend project: map letters to numbers, add them up, reduce to one digit. The life path number really is about ten lines of JavaScript, and we’ll write it below. A full chart is a different job, and it’s worth knowing why before you decide whether to build or call an API.

A correct life path number in JavaScript

The life path comes from the date of birth alone. The correct method reduces the month, the day and the year separately, keeping the master numbers 11, 22 and 33, then adds the three and reduces again:

const MASTERS = new Set([11, 22, 33]);

function reduce(n) {
  while (n >= 10 && !MASTERS.has(n)) {
    n = String(n).split("").reduce((sum, d) => sum + Number(d), 0);
  }
  return n;
}

function lifePath(birthdate) {            // "YYYY-MM-DD"
  const [year, month, day] = birthdate.split("-").map(Number);
  return reduce(reduce(month) + reduce(day) + reduce(year));
}

lifePath("1990-03-12");   // 7
lifePath("1980-12-08");   // 2

The common shortcut adds every digit of the date at once. For 1980-12-08 it gives 29, then 11, a master number that isn’t there. The correct answer is 2. How to calculate a life path number walks through why.

Where it gets harder

The life path is the easy one. The name-based numbers bring in conventions that numerology sources disagree on, and each choice changes the result:

  • Is Y a vowel? It depends on the source. Treating Y as a vowel changes the soul urge and personality numbers of every name that contains one. See is Y a vowel in numerology.
  • Accents and non-Latin letters. “María” and “José” need folding to A–Z before lookup. Silently dropping the accented letter is a common bug.
  • Whole name or name by name? Summing the whole name and reducing once gives a different destiny number from reducing each name first and adding the results.
  • Middle names and compound surnames. Some numbers use the full birth name and others use the first name only.
  • Karmic debts (13, 14, 16, 19) come from the unreduced intermediate totals, so you have to keep those around.
  • Pinnacles and challenges need single-digit inputs, while the birthday number shown to users keeps its master numbers. Mixing these up puts challenges outside their valid range.

None of this is hard to code. The hard part is choosing an answer to each question, documenting it and never changing it, because every chart you’ve stored depends on it.

Calling an API instead

A numerology API has already made those choices. Here is the whole integration in Node.js with plain fetch:

const res = await fetch("https://simplenumerologyapi.com/v1/charts/pythagorean", {
  method: "POST",
  headers: {
    "content-type": "application/json",
    "X-API-Key": process.env.NUMEROLOGY_API_KEY,
  },
  body: JSON.stringify({
    first_name: "María",
    middle_name: "Stefania",
    last_name: "García López",
    birthdate: "1990-03-12",
  }),
});
const chart = await res.json();
chart.life_path_number;     // 7
chart.destiny_number;       // 5
chart.karmic_debt_numbers;  // [13]

That call returns 47 fields: life path, destiny, soul urge, personality, maturity, karmic lessons and debts, hidden passion, planes of expression, pinnacles, challenges and life cycles. The Y rule and the reduction method can be changed per request, and every response states the conventions it used.

Which should you choose?

Write it yourself if you only need the life path number, or if numerology is the core of your product and you want to own every convention. The ten lines above are correct.

Use an API if you need more than two or three numbers, if you support names with accents, or if you’d rather not maintain the edge cases. The free plan covers 100 charts a month, which is plenty for a side project, and charts are deterministic, so you can cache each one forever.

One rule applies either way: don’t call the API from the browser. Keys are server credentials. Call it from a route handler, a serverless function or an edge function. The JavaScript quickstart has a Next.js example.

Compute this properly, in one request

47 Pythagorean fields from a name and a date of birth, to the conventions described above. 100 charts a month free, no card. Quickstarts for Python and JavaScript.

Get a free key

Keep reading