meihua-ts-lib
v0.1.0
Published
梅花易数排盘 TypeScript 库,支持传统时间起卦、数值化起卦、本互变与体用五行关系。
Downloads
179
Readme
meihua-ts-lib
梅花易数排盘 TypeScript 库。首版聚焦排盘数据:起卦、本卦、互卦、变卦、动爻、体用与五行关系,不输出断语,也不实现纳甲、六亲、世应、六神。
安装
bun add meihua-ts-lib也可以用 npm、pnpm、yarn 安装;包同时提供 ESM、CJS 和 TypeScript 类型声明。
时间起卦
时间起卦采用传统梅花口径:农历年支数、农历月、农历日、时支数。公历输入会通过 tyme4ts 转为农历。
import { qiGuaByTime } from "meihua-ts-lib";
const chart = qiGuaByTime({
calendar: "lunar",
year: 2024,
month: 3,
day: 17,
hour: 16,
});
console.log(chart.mainHexagram.fullName); // 天泽履
console.log(chart.movingLine); // 4
console.log(chart.changedHexagram.fullName); // 风泽中孚
console.log(chart.mutualHexagram.fullName); // 风火家人
console.log(chart.oppositeHexagram.fullName); // 地山谦
console.log(chart.reversedHexagram.fullName); // 风天小畜
console.log(chart.time?.ganzhi.day.name); // 己未
console.log(chart.time?.dayVoidBranches.map((branch) => branch.name)); // ["子", "丑"]公历输入:
import { qiGuaByTime } from "meihua-ts-lib";
const chart = qiGuaByTime({
calendar: "solar",
year: 2024,
month: 4,
day: 25,
hour: 16,
});数值化起卦
报数、字数、声音、物数、方位外应等方法在首版中统一为数值化入口。库不内置汉字笔画数据;调用方先把笔画、字数、物数或外应转换成数字。
import { qiGuaByCounts } from "meihua-ts-lib";
const chart = qiGuaByCounts({
method: "word",
upper: 9,
lower: 10,
moving: 10,
label: "字占示例",
});取数规则:
上卦 = upper 对 8 取余,余 0 作 8
下卦 = lower 对 8 取余,余 0 作 8
动爻 = moving 对 6 取余,余 0 作 6不传 moving 时使用 upper + lower。
直接按卦起盘
import { qiGuaByTrigrams } from "meihua-ts-lib";
const chart = qiGuaByTrigrams({
upper: "乾",
lower: "兑",
movingLine: 4,
});八卦键名直接使用中文卦名:
乾 兑 离 震 巽 坎 艮 坤结果结构
{
mainHexagram,
mutualHexagram,
changedHexagram,
oppositeHexagram,
reversedHexagram,
movingLine,
body,
use,
elementRelation,
source,
time
}爻序始终自下而上。elementRelation 只表达体用五行关系,例如 same、useGeneratesBody、bodyGeneratesUse、useControlsBody、bodyControlsUse,不输出吉凶断语。
time 只在 qiGuaByTime 中返回,包含阳历时间、农历时间、年月日时干支,以及各柱对应旬空;其中 dayVoidBranches 是排盘常用的日旬空快捷字段。
开发
bun install
bun run typecheck
bun test
bun run build
bun run test:dist