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 +70 -23
- package/dist/index.cjs.map +1 -1
- package/dist/index.d.ts +40 -5
- package/dist/index.js +70 -23
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
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
|
|
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
|
|
212
|
-
|
|
213
|
-
|
|
214
|
-
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
219
|
-
|
|
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(
|
|
5421
|
-
if (
|
|
5422
|
-
if (SHENG[
|
|
5423
|
-
if (SHENG[
|
|
5424
|
-
if (KE[
|
|
5425
|
-
if (KE[
|
|
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 =
|
|
5552
|
-
const upperGua =
|
|
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 =
|
|
5592
|
-
const upperTrigram =
|
|
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 =
|
|
5679
|
-
const pureUpperTrigram =
|
|
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
|