iching-shifa 1.0.0 → 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.cjs CHANGED
@@ -145,9 +145,9 @@ function timeQiGua(year, month, day, hour, lunarMonth, lunarDay, yearZhi, hourZh
145
145
  const hzCode = diZhiArr.indexOf(hourZhi) + 1;
146
146
  const cm = lunarMonth;
147
147
  const cd = lunarDay;
148
- let upperNum = (yzCode + cm + cd) % 8;
148
+ let upperNum = (yzCode + cm + cd + hzCode) % 8;
149
149
  if (upperNum === 0) upperNum = 8;
150
- let lowerNum = (yzCode + cm + cd + hzCode) % 8;
150
+ let lowerNum = (yzCode + cm + cd) % 8;
151
151
  if (lowerNum === 0) lowerNum = 8;
152
152
  let dongYao = (yzCode + cm + cd + hzCode) % 6;
153
153
  if (dongYao === 0) dongYao = 6;
@@ -208,16 +208,51 @@ function getMovingYaoPositions(yaoString) {
208
208
  }
209
209
  return positions;
210
210
  }
211
- const TRIGRAM_TO_BAGUA = {
212
- "797999997779797979979777979779977777977777777799799799997999997997979799999779799979779997997977977777797777997977797999779779977797997799779797779979999799977999777799999979777999797979977797": "",
213
- "776796976778778978976978798976976998998796776976776998996998998796778978798798978776998996796778776978996996798776976798996778796978798796798778978776996996998776798998996778976778978976796796": "",
214
- "967987769989987767787767967767969789967967969789789969987789767787987969989787967769767769989769767787989767787969787787987769767969987967989967789787967769987989789769989789969987769789989969": "",
215
- "766966788788786786786966966766988986788986986988768986966786766988968986968788968786768988988786966768788786986988968986988788768968768786968966766766966766766968766788988968966768788768986768": "",
216
- "877877699697699879697899699677879679879897679877879877677677877699879897679699899897897899677877897677699697877897899677897899897677679679679679697899699879879697697877679697677699899697899879": "",
217
- "878696678696876678876878696896876896676676698898698878876898878898878878676676696678696878698698876898676698678676896878698876696696898678898698678678896678898876896696876676896698676898896896": "",
218
- "867689687667867689669867867867667687869689889689689869669667669869887867689687887669687669889669889869687867889669869887887667667667889889687889887869669687887667869887689889869887687867667689": "",
219
- "886688666686688666866668668888886868686886688868666686688888668686886866666668888686666868668886888666866866688868686868868868668666886866688686866866866668668886888888686886666688888868888688": ""
211
+ const NUM_TO_TRIGRAM = {
212
+ 1: "777",
213
+ 2: "778",
214
+ 3: "787",
215
+ 4: "788",
216
+ 5: "877",
217
+ 6: "878",
218
+ 7: "887",
219
+ 8: "888"
220
220
  };
221
+ function modWithZero(num, divisor) {
222
+ const remainder = num % divisor;
223
+ return remainder === 0 ? divisor : remainder;
224
+ }
225
+ function buildYaoString(upperNum, lowerNum, dongYao) {
226
+ const yaoArray = (NUM_TO_TRIGRAM[lowerNum] + NUM_TO_TRIGRAM[upperNum]).split("").map((c) => parseInt(c, 10));
227
+ const dongIndex = dongYao - 1;
228
+ if (yaoArray[dongIndex] === 7) {
229
+ yaoArray[dongIndex] = 9;
230
+ } else if (yaoArray[dongIndex] === 8) {
231
+ yaoArray[dongIndex] = 6;
232
+ }
233
+ return yaoArray.join("");
234
+ }
235
+ function threeNumberQiGua(num1, num2, num3) {
236
+ const upperNum = modWithZero(num1, 8);
237
+ const lowerNum = modWithZero(num2, 8);
238
+ const dongYao = modWithZero(num3, 6);
239
+ return buildYaoString(upperNum, lowerNum, dongYao);
240
+ }
241
+ function numberArrayQiGua(numbers, hourZhiIndex) {
242
+ if (numbers.length < 2) {
243
+ throw new Error("数组起卦至少需要2个数字");
244
+ }
245
+ const len = numbers.length;
246
+ const splitIndex = Math.floor(len / 2);
247
+ const firstHalf = numbers.slice(0, splitIndex);
248
+ const secondHalf = numbers.slice(splitIndex);
249
+ const firstSum = firstHalf.reduce((a, b) => a + b, 0);
250
+ const secondSum = secondHalf.reduce((a, b) => a + b, 0);
251
+ const upperNum = modWithZero(firstSum, 8);
252
+ const lowerNum = modWithZero(secondSum, 8);
253
+ const dongYao = modWithZero(upperNum + lowerNum + hourZhiIndex, 6);
254
+ return buildYaoString(upperNum, lowerNum, dongYao);
255
+ }
221
256
  const BAGUA_XIANG = {
222
257
  "1": "天",
223
258
  "2": "澤",
@@ -228,6 +263,16 @@ const BAGUA_XIANG = {
228
263
  "7": "山",
229
264
  "8": "地"
230
265
  };
266
+ const CODE_TO_BAGUA = {
267
+ "777": "乾",
268
+ "778": "兑",
269
+ "787": "离",
270
+ "788": "震",
271
+ "877": "巽",
272
+ "878": "坎",
273
+ "887": "艮",
274
+ "888": "坤"
275
+ };
231
276
  const GUA64_ORDER = [
232
277
  "乾",
233
278
  "姤",
@@ -5417,12 +5462,12 @@ function ganZhiToWuXing(ganOrZhi) {
5417
5462
  }
5418
5463
  return wx;
5419
5464
  }
5420
- function getWuXingRelation(a, b) {
5421
- if (a === b) return "比和";
5422
- if (SHENG[b] === a) return "生我";
5423
- if (SHENG[a] === b) return "我生";
5424
- if (KE[b] === a) return "尅我";
5425
- if (KE[a] === b) return "我尅";
5465
+ function getWuXingRelation(yaoWx, gongWx) {
5466
+ if (yaoWx === gongWx) return "比和";
5467
+ if (SHENG[yaoWx] === gongWx) return "生我";
5468
+ if (SHENG[gongWx] === yaoWx) return "我生";
5469
+ if (KE[yaoWx] === gongWx) return "尅我";
5470
+ if (KE[gongWx] === yaoWx) return "我尅";
5426
5471
  return "比和";
5427
5472
  }
5428
5473
  function wuXingToLiuQin(yaoWuXing, gongWuXing) {
@@ -5548,8 +5593,8 @@ function getGuaName(yaoString) {
5548
5593
  }
5549
5594
  const lower = staticYao.slice(0, 3);
5550
5595
  const upper = staticYao.slice(3, 6);
5551
- const lowerGua = TRIGRAM_TO_BAGUA[lower];
5552
- const upperGua = TRIGRAM_TO_BAGUA[upper];
5596
+ const lowerGua = CODE_TO_BAGUA[lower];
5597
+ const upperGua = CODE_TO_BAGUA[upper];
5553
5598
  if (lowerGua && upperGua) {
5554
5599
  return findGuaByTrigrams(lowerGua, upperGua) || `${lowerGua}${upperGua}`;
5555
5600
  }
@@ -5588,8 +5633,8 @@ function decodeGua(yaoString, dayGanZhi, isZhiGua = false) {
5588
5633
  const palaceLevel = GUA_PALACE_LEVEL[guaName] || "本宮";
5589
5634
  const palaceWuXing = PALACE_WUXING[palace] || "金";
5590
5635
  const staticYao = yaoString.replace(/9/g, "7").replace(/6/g, "8");
5591
- const lowerTrigram = TRIGRAM_TO_BAGUA[staticYao.slice(0, 3)] || "乾";
5592
- const upperTrigram = TRIGRAM_TO_BAGUA[staticYao.slice(3, 6)] || "乾";
5636
+ const lowerTrigram = CODE_TO_BAGUA[staticYao.slice(0, 3)] || "乾";
5637
+ const upperTrigram = CODE_TO_BAGUA[staticYao.slice(3, 6)] || "乾";
5593
5638
  const lowerNajiaRaw = NAJIA_LOWER[lowerTrigram] || [];
5594
5639
  const upperNajiaRaw = NAJIA_UPPER[upperTrigram] || [];
5595
5640
  const parseNajia = (item) => {
@@ -5675,8 +5720,8 @@ function findFuShen(yaoList, palace, palaceWuXing) {
5675
5720
  return void 0;
5676
5721
  }
5677
5722
  const pureCode = PALACE_PURE_CODE[palace] || "777777";
5678
- const pureLowerTrigram = TRIGRAM_TO_BAGUA[pureCode.slice(0, 3)] || "乾";
5679
- const pureUpperTrigram = TRIGRAM_TO_BAGUA[pureCode.slice(3, 6)] || "乾";
5723
+ const pureLowerTrigram = CODE_TO_BAGUA[pureCode.slice(0, 3)] || "乾";
5724
+ const pureUpperTrigram = CODE_TO_BAGUA[pureCode.slice(3, 6)] || "乾";
5680
5725
  const pureLowerNajiaRaw = NAJIA_LOWER[pureLowerTrigram] || [];
5681
5726
  const pureUpperNajiaRaw = NAJIA_UPPER[pureUpperTrigram] || [];
5682
5727
  const parseNajia = (item) => {
@@ -5859,9 +5904,11 @@ exports.getWuXingRelation = getWuXingRelation;
5859
5904
  exports.getZhiGua = getZhiGua;
5860
5905
  exports.isMovingYao = isMovingYao;
5861
5906
  exports.manualQiGua = manualQiGua;
5907
+ exports.numberArrayQiGua = numberArrayQiGua;
5862
5908
  exports.rotateList = rotateList;
5863
5909
  exports.rotateListByIndex = rotateListByIndex;
5864
5910
  exports.solarToLunar = solarToLunar;
5911
+ exports.threeNumberQiGua = threeNumberQiGua;
5865
5912
  exports.timeQiGua = timeQiGua;
5866
5913
  exports.wuXingToLiuQin = wuXingToLiuQin;
5867
5914
  //# sourceMappingURL=index.cjs.map