kaabalah 1.0.4 → 1.1.0

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/dist/index.mjs CHANGED
@@ -5806,99 +5806,107 @@ var calculateGematria = (word, options = {}, tree) => {
5806
5806
  if (!tree) {
5807
5807
  tree = createTree({ system: SYSTEM2, parts: [] });
5808
5808
  }
5809
- const includedLetters = /* @__PURE__ */ new Map();
5810
- const letters = word.toUpperCase().split("");
5809
+ const includedLetters = [];
5810
+ const words = word.toUpperCase().trim().split(" ");
5811
5811
  let vowelsSum = 0;
5812
5812
  let consonantsSum = 0;
5813
- const presentGematriaNumbers = /* @__PURE__ */ new Set();
5814
- for (let i = 0; i < letters.length; i++) {
5815
- const letter = letters[i].toLocaleUpperCase();
5816
- const nextLetter = letters[i + 1]?.toLocaleLowerCase() || "";
5817
- if (["P", "T", "K", "S", "C"].includes(letter) && nextLetter) {
5818
- const combinedLetter = letter + nextLetter;
5819
- const isEnding2 = i > 0 && i === letters.length - 2;
5820
- const [mapping2] = tree.walk(`letter:${combinedLetter}`, 2, "hebrewLetter");
5821
- if (mapping2?.data) {
5822
- let value = mapping2.data.gematriaValue;
5823
- if (isEnding2 && mapping2.data.gematriaValueWhenEnding !== void 0) {
5824
- value = mapping2.data.gematriaValueWhenEnding;
5813
+ const includedGematriaValues = /* @__PURE__ */ new Set();
5814
+ const letterPercentages = {
5815
+ percentageOfVowels: 0,
5816
+ percentageOfConsonants: 0,
5817
+ letters: {}
5818
+ };
5819
+ for (const word2 of words) {
5820
+ const letters = word2.split("");
5821
+ for (let i = 0; i < letters.length; i++) {
5822
+ const letter = letters[i].toLocaleUpperCase();
5823
+ const nextLetter = letters[i + 1]?.toLocaleLowerCase() || "";
5824
+ if (["P", "T", "K", "S", "C"].includes(letter) && nextLetter) {
5825
+ const combinedLetter = letter + nextLetter;
5826
+ const isEnding2 = i > 0 && i === letters.length - 2;
5827
+ const latinLetterId2 = `letter:${combinedLetter}`;
5828
+ const [mapping2] = tree.walk(latinLetterId2, 2, "hebrewLetter");
5829
+ if (mapping2?.data) {
5830
+ let value = mapping2.data.gematriaValue;
5831
+ if (isEnding2 && mapping2.data.gematriaValueWhenEnding !== void 0) {
5832
+ value = mapping2.data.gematriaValueWhenEnding;
5833
+ }
5834
+ includedGematriaValues.add(value);
5835
+ includedLetters.push({ latinLetterId: latinLetterId2, value, hebrewLetterId: mapping2.id, isVowel: isVowel(letter) });
5836
+ consonantsSum += value;
5837
+ i++;
5838
+ continue;
5825
5839
  }
5826
- presentGematriaNumbers.add(value);
5827
- includedLetters.set(mapping2.id, { letter: combinedLetter, value, hebrewLetter: mapping2.data, isVowel: isVowel(letter) });
5828
- consonantsSum += value;
5829
- i++;
5830
- continue;
5831
- }
5832
- }
5833
- let mapping;
5834
- const isStarting = i === 0;
5835
- if (isStarting && letter === "O") {
5836
- mapping = tree.getNode(`letter:${HEBREW_LETTERS.AIN}`);
5837
- } else {
5838
- mapping = tree.walk(`letter:${letter}`, 2, "hebrewLetter").at(0);
5839
- }
5840
- const isEnding = i > 0 && i === letters.length - 1;
5841
- if (mapping?.data) {
5842
- let value = mapping.data.gematriaValue;
5843
- if (isEnding && mapping.data.gematriaValueWhenEnding !== void 0) {
5844
- value = mapping.data.gematriaValueWhenEnding;
5845
5840
  }
5846
- presentGematriaNumbers.add(value);
5847
- includedLetters.set(mapping.id, { letter, value, hebrewLetter: mapping.data, isVowel: isVowel(letter) });
5848
- if (isVowel(letter)) {
5849
- vowelsSum += value;
5841
+ let mapping;
5842
+ let latinLetterId = `letter:${letter}`;
5843
+ const isStarting = i === 0;
5844
+ if (isStarting && letter === "O") {
5845
+ latinLetterId = `letter:${HEBREW_LETTERS.AIN}`;
5846
+ mapping = tree.getNode(latinLetterId);
5850
5847
  } else {
5851
- consonantsSum += value;
5848
+ mapping = tree.walk(latinLetterId, 2, "hebrewLetter").at(0);
5849
+ }
5850
+ const isEnding = i > 0 && i === letters.length - 1;
5851
+ if (mapping?.data) {
5852
+ let value = mapping.data.gematriaValue;
5853
+ if (isEnding && mapping.data.gematriaValueWhenEnding !== void 0) {
5854
+ value = mapping.data.gematriaValueWhenEnding;
5855
+ }
5856
+ includedGematriaValues.add(value);
5857
+ includedLetters.push({ latinLetterId, value, hebrewLetterId: mapping.id, isVowel: isVowel(letter) });
5858
+ if (isVowel(letter)) {
5859
+ vowelsSum += value;
5860
+ } else {
5861
+ consonantsSum += value;
5862
+ }
5852
5863
  }
5853
5864
  }
5865
+ if (options?.calculateLetterPercentages) {
5866
+ const letterCount = letters.length;
5867
+ let vowelsCount = 0;
5868
+ let consonantsCount = 0;
5869
+ for (const letter of new Set(letters)) {
5870
+ const occurrences = letters.filter((l) => l === letter).length;
5871
+ letterPercentages.letters[letter] = occurrences / letterCount * 100;
5872
+ if (isVowel(letter)) {
5873
+ vowelsCount += occurrences;
5874
+ } else {
5875
+ consonantsCount += occurrences;
5876
+ }
5877
+ }
5878
+ letterPercentages.percentageOfVowels = vowelsCount / letterCount * 100;
5879
+ letterPercentages.percentageOfConsonants = consonantsCount / letterCount * 100;
5880
+ }
5854
5881
  }
5855
5882
  const vowelsReduction = reduceToSingleDigitWithSteps(vowelsSum);
5856
5883
  const consonantsReduction = reduceToSingleDigitWithSteps(consonantsSum);
5857
5884
  const synthesisReduction = reduceToSingleDigitWithSteps(
5858
5885
  vowelsSum + consonantsSum
5859
5886
  );
5860
- const missingGematriaNumbers = [];
5861
- if (options?.calculateMissingGematriaNumbers) {
5887
+ const missingGematriaValues = [];
5888
+ if (options?.calculateMissingGematriaValues) {
5862
5889
  for (const hebrewLetter of Object.values(HEBREW_LETTERS)) {
5863
5890
  const hebrewLetterNode = tree.getNode(`letter:${hebrewLetter}`);
5864
5891
  if (!hebrewLetterNode?.data) {
5865
5892
  continue;
5866
5893
  }
5867
- if (!presentGematriaNumbers.has(hebrewLetterNode.data.gematriaValue)) {
5868
- missingGematriaNumbers.push({
5869
- number: hebrewLetterNode.data.gematriaValue,
5870
- letter: hebrewLetter
5894
+ if (!includedGematriaValues.has(hebrewLetterNode.data.gematriaValue)) {
5895
+ missingGematriaValues.push({
5896
+ value: hebrewLetterNode.data.gematriaValue,
5897
+ hebrewLetter,
5898
+ whenEnding: false
5871
5899
  });
5872
5900
  }
5873
- if (hebrewLetterNode.data.gematriaValueWhenEnding && !presentGematriaNumbers.has(hebrewLetterNode.data.gematriaValueWhenEnding)) {
5874
- missingGematriaNumbers.push({
5875
- number: hebrewLetterNode.data.gematriaValueWhenEnding,
5876
- letter: `${hebrewLetter} (on ending)`
5901
+ if (hebrewLetterNode.data.gematriaValueWhenEnding && !includedGematriaValues.has(hebrewLetterNode.data.gematriaValueWhenEnding)) {
5902
+ missingGematriaValues.push({
5903
+ value: hebrewLetterNode.data.gematriaValueWhenEnding,
5904
+ hebrewLetter,
5905
+ whenEnding: true
5877
5906
  });
5878
5907
  }
5879
5908
  }
5880
- missingGematriaNumbers.sort((a, b) => a.number - b.number);
5881
- }
5882
- const letterPercentages = {
5883
- percentageOfVowels: 0,
5884
- percentageOfConsonants: 0,
5885
- letters: {}
5886
- };
5887
- if (options?.calculateLetterPercentage) {
5888
- const letterCount = letters.length;
5889
- let vowelsCount = 0;
5890
- let consonantsCount = 0;
5891
- for (const [_, letter] of includedLetters) {
5892
- const occurrences = letters.filter((l) => l === letter.letter).length;
5893
- letterPercentages.letters[letter.letter] = occurrences / letterCount * 100;
5894
- if (letter.isVowel) {
5895
- vowelsCount += occurrences;
5896
- } else {
5897
- consonantsCount += occurrences;
5898
- }
5899
- }
5900
- letterPercentages.percentageOfVowels = vowelsCount / letterCount * 100;
5901
- letterPercentages.percentageOfConsonants = consonantsCount / letterCount * 100;
5909
+ missingGematriaValues.sort((a, b) => a.value - b.value);
5902
5910
  }
5903
5911
  return {
5904
5912
  vowels: {
@@ -5917,8 +5925,8 @@ var calculateGematria = (word, options = {}, tree) => {
5917
5925
  finalValue: synthesisReduction.finalValue
5918
5926
  },
5919
5927
  includedLetters,
5920
- missingGematriaNumbers: options?.calculateMissingGematriaNumbers ? missingGematriaNumbers : void 0,
5921
- letterPercentages: options?.calculateLetterPercentage ? letterPercentages : void 0
5928
+ missingGematriaValues: options?.calculateMissingGematriaValues ? missingGematriaValues : void 0,
5929
+ letterPercentages: options?.calculateLetterPercentages ? letterPercentages : void 0
5922
5930
  };
5923
5931
  };
5924
5932