iching-shifa 1.0.1 → 1.2.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
@@ -208,6 +208,62 @@ function getMovingYaoPositions(yaoString) {
208
208
  }
209
209
  return positions;
210
210
  }
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
+ };
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 lueshifaOnce(groupSize) {
236
+ const left = 1 + Math.floor(Math.random() * 48);
237
+ const remainder = left % groupSize;
238
+ return remainder === 0 ? 1 : remainder + 1;
239
+ }
240
+ function lueshifa() {
241
+ const lowerNum = lueshifaOnce(8);
242
+ const upperNum = lueshifaOnce(8);
243
+ const dongYao = lueshifaOnce(6);
244
+ return buildYaoString(upperNum, lowerNum, dongYao);
245
+ }
246
+ function threeNumberQiGua(num1, num2, num3) {
247
+ const upperNum = modWithZero(num1, 8);
248
+ const lowerNum = modWithZero(num2, 8);
249
+ const dongYao = modWithZero(num3, 6);
250
+ return buildYaoString(upperNum, lowerNum, dongYao);
251
+ }
252
+ function numberArrayQiGua(numbers, hourZhiIndex) {
253
+ if (numbers.length < 2) {
254
+ throw new Error("数组起卦至少需要2个数字");
255
+ }
256
+ const len = numbers.length;
257
+ const splitIndex = Math.floor(len / 2);
258
+ const firstHalf = numbers.slice(0, splitIndex);
259
+ const secondHalf = numbers.slice(splitIndex);
260
+ const firstSum = firstHalf.reduce((a, b) => a + b, 0);
261
+ const secondSum = secondHalf.reduce((a, b) => a + b, 0);
262
+ const upperNum = modWithZero(firstSum, 8);
263
+ const lowerNum = modWithZero(secondSum, 8);
264
+ const dongYao = modWithZero(upperNum + lowerNum + hourZhiIndex, 6);
265
+ return buildYaoString(upperNum, lowerNum, dongYao);
266
+ }
211
267
  const BAGUA_XIANG = {
212
268
  "1": "天",
213
269
  "2": "澤",
@@ -5858,10 +5914,13 @@ exports.getMovingYaoPositions = getMovingYaoPositions;
5858
5914
  exports.getWuXingRelation = getWuXingRelation;
5859
5915
  exports.getZhiGua = getZhiGua;
5860
5916
  exports.isMovingYao = isMovingYao;
5917
+ exports.lueshifa = lueshifa;
5861
5918
  exports.manualQiGua = manualQiGua;
5919
+ exports.numberArrayQiGua = numberArrayQiGua;
5862
5920
  exports.rotateList = rotateList;
5863
5921
  exports.rotateListByIndex = rotateListByIndex;
5864
5922
  exports.solarToLunar = solarToLunar;
5923
+ exports.threeNumberQiGua = threeNumberQiGua;
5865
5924
  exports.timeQiGua = timeQiGua;
5866
5925
  exports.wuXingToLiuQin = wuXingToLiuQin;
5867
5926
  //# sourceMappingURL=index.cjs.map