mingyu-core 0.1.0 → 0.1.1

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/README.md CHANGED
@@ -1,90 +1,277 @@
1
- # mingyu-core
1
+ # mingyu-core · 命理核心算法库
2
2
 
3
- Mingyu (命理) core algorithms - a comprehensive TypeScript package for traditional Chinese metaphysics and divination.
3
+ > 中国传统命理与占卜算法的 TypeScript 实现,覆盖八字、紫微斗数、奇门遁甲、六爻、六壬、梅花易数等主流术数。
4
4
 
5
- **⚠️ Important Disclaimer:** This library provides algorithmic implementations only. All results are for **reference and entertainment purposes only**. Nothing in this package should be construed as professional advice, fortune-telling, or predictions of any kind. The authors assume no responsibility for decisions made based on the output of these algorithms.
5
+ [![npm version](https://img.shields.io/npm/v/mingyu-core.svg)](https://www.npmjs.com/package/mingyu-core)
6
+ [![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](LICENSE)
6
7
 
7
- ## Installation
8
+ ---
9
+
10
+ ## ⚠️ 重要免责声明
11
+
12
+ **本库仅提供算法实现,所有结果仅供参考、学习与娱乐使用,不构成任何命理预测、专业建议或决策依据。** 命理术数存在流派差异,本库按主流公认理法实现,不代表唯一正确解释。使用者应对基于本库输出的任何判断与决策自行承担责任,作者不承担任何因使用本库而产生的后果。
13
+
14
+ 命理仅供参考,**请勿用于重大人生决策**(医疗、法律、投资、婚姻等),遇专业问题请咨询相关领域专业人士。
15
+
16
+ ---
17
+
18
+ ## 简介
19
+
20
+ `mingyu-core` 是开源命理项目 [mingyu](https://github.com/Brhiza/mingyu) 抽取的核心算法包,将排盘、起卦、抽牌、结构化数据计算等纯算法逻辑独立封装,供其他项目以 npm 依赖形式复用,避免各项目各自维护一份命理代码。
21
+
22
+ 所有算法均对照传统古籍实现,并在源码中标注法理依据:
23
+
24
+ | 术数 | 古籍依据 |
25
+ |------|----------|
26
+ | 八字 | 《渊海子平》《三命通会》《子平真诠》《穷通宝鉴》 |
27
+ | 六爻 | 《卜筮正宗》《增删卜易》 |
28
+ | 梅花易数 | 《梅花易数》 |
29
+ | 奇门遁甲 | 《烟波钓叟歌》《遁甲演义》《奇门遁甲秘籍大全》 |
30
+ | 大六壬 | 《大六壬大全》《大六壬指南》 |
31
+ | 择日 | 《协纪辨方书》《象吉通书》 |
32
+ | 紫微斗数 | 《紫微斗数全书》 |
33
+
34
+ ---
35
+
36
+ ## 安装
8
37
 
9
38
  ```bash
10
39
  npm install mingyu-core
40
+ # 或
41
+ pnpm add mingyu-core
42
+ # 或
43
+ yarn add mingyu-core
11
44
  ```
12
45
 
13
- ## Features
14
-
15
- | Module | Description | Status |
16
- |--------|-------------|--------|
17
- | **Bazi (八字)** | Four Pillars of Destiny - birth chart calculation, Shensha (神煞), strength analysis, pattern recognition, useful god determination | ✅ |
18
- | **Qimen Dunjia (奇门遁甲)** | Mysterious Gate - rotating plate method, 81 patterns, direction advice, yingqi timing | ✅ |
19
- | **Liuyao (六爻)** | Six Lines - Jingfang eight-palace method, Najia (纳甲), Shiying (世应), Six Animals | ✅ |
20
- | **Meihua Yishu (梅花易数)** | Plum Blossom Divination - 5 divination methods, Ti-Yong analysis, mutual/derived hexagrams | ✅ |
21
- | **Da Liuren (大六壬)** | Great Six Ren - moon leader, nobleman, four lessons, three transmissions, nine categories | ✅ |
22
- | **Xiao Liuren (小六壬)** | Small Six Ren - time/number/random divination, six palaces | |
23
- | **Almanac (择日)** | Day selection - auspicious/inauspicious days, Xuan Kong Fei Xing, Peng Zu prohibitions | ✅ |
24
- | **SSGW (灵签)** | Deity oracle - random sign drawing | |
25
- | **Lenormand (雷诺曼)** | Lenormand cards - 8 spread types, card combinations | |
26
- | **Western Astrology (星盘)** | Natal chart, Placidus houses, aspects, transits | |
27
- | **Ziwei Doushu (紫微斗数)** | Purple Star - analysis payload, pattern detection, evidence pool | |
28
- | **Calendar (历法)** | Lunar calendar, ganzhi (干支), solar terms, void branches | |
29
-
30
- ## Usage
46
+ 外部依赖:
47
+ - `tyme4ts`(历法计算,作为依赖自动安装)
48
+ - `iztro`(紫微斗数,可选,使用紫微模块时需要)
49
+ - `celestine`(西洋占星,可选,使用星盘模块时需要)
50
+
51
+ ---
52
+
53
+ ## 模块总览
54
+
55
+ | 模块 | 子路径 | 说明 |
56
+ |------|--------|------|
57
+ | **八字 Bazi** | `mingyu-core/bazi` | 四柱排盘、神煞、调候用神、格局、大运、五行强度,含透干根气、十神结构、合化评估、命卦、小运等增强分析 |
58
+ | **六爻 Liuyao** | `mingyu-core/divination/liuyao` | 京房八宫法、纳甲、世应、六亲六神、月破日破、化进退神 |
59
+ | **梅花易数 Meihua** | `mingyu-core/divination/meihua` | 时间/数字/随机/外应/时辰纳卦五种起卦法、体用生克 |
60
+ | **奇门遁甲 Qimen** | `mingyu-core/divination/qimen` | 转盘法、拆补定局、九九八十一格、经典格局、方位应期 |
61
+ | **大六壬 Liuren** | `mingyu-core/divination/liuren` | 月将、贵人、九宗门取传、三传、天将、神煞 |
62
+ | **小六壬 Xiaoliuren** | `mingyu-core/divination/xiaoliuren` | 六宫掌诀、五行生克、月令旺衰 |
63
+ | **择日 Almanac** | `mingyu-core/divination/almanac` | 黄历择日、神煞评分、二十八宿、彭祖百忌 |
64
+ | **灵签 SSGW** | `mingyu-core/divination/ssgw` | 三山国王 92 签随机抽签 |
65
+ | **雷诺曼 Lenormand** | `mingyu-core/divination/lenormand` | 36 张牌、8 种牌阵、牌义组合 |
66
+ | **西洋占星 Astrolabe** | `mingyu-core/divination/astrolabe` | 本命盘、Placidus 宫位、十大相位、行运 |
67
+ | **紫微斗数 Ziwei** | `mingyu-core/ziwei/iztro` | iztro 封装、35 格局检测、证据池、大限时间线 |
68
+ | **历法 Calendar** | `mingyu-core/calendar` | 农历、干支、节气、空亡、真太阳时 |
69
+ | **类型 Types** | `mingyu-core/types` | 所有共享类型定义 |
70
+
71
+ ---
72
+
73
+ ## 快速开始
74
+
75
+ ### 八字排盘
31
76
 
32
77
  ```typescript
33
- // Bazi calculation
34
78
  import { baziCalculator } from 'mingyu-core/bazi';
79
+ import type { BaziChartResult } from 'mingyu-core/types';
35
80
 
36
- const result = baziCalculator.calculateBazi({
81
+ // timeIndex: 0=早子时, 1=丑时, ..., 11=亥时, 12=晚子时
82
+ const result: BaziChartResult = baziCalculator.calculateBazi({
37
83
  year: 1990,
38
- month: 1,
84
+ month: 1, // 1-12
39
85
  day: 1,
86
+ timeIndex: 5, // 巳时
87
+ gender: 'male', // 'male' | 'female'
88
+ });
89
+
90
+ console.log(result.pillars);
91
+ // { year: {gan:'庚', zhi:'午', ganZhi:'庚午'},
92
+ // month: {gan:'丁', zhi:'丑', ganZhi:'丁丑'},
93
+ // day: {gan:'乙', zhi:'未', ganZhi:'乙未'},
94
+ // hour: {gan:'丁', zhi:'亥', ganZhi:'丁亥'} }
95
+
96
+ console.log(result.dayMaster); // { gan:'乙', element:'木', yinYang:'阴' }
97
+ console.log(result.shensha); // 各柱神煞
98
+ console.log(result.analysis); // 强度、格局、用神
99
+ console.log(result.luckInfo); // 大运
100
+ ```
101
+
102
+ ### 农历输入与真太阳时
103
+
104
+ ```typescript
105
+ const result = baziCalculator.calculateBazi({
106
+ year: 1990, month: 12, day: 5, // 农历
40
107
  timeIndex: 5,
41
108
  gender: 'male',
109
+ isLunar: true, // 农历输入
110
+ isLeapMonth: false, // 是否闰月
42
111
  });
43
112
 
44
- // Qimen Dunjia
45
- import { generateQimen } from 'mingyu-core/divination/qimen';
46
- const qimenData = generateQimen(new Date('2025-01-01T10:00:00'));
113
+ // 真太阳时(按出生地经度校正)
114
+ const result2 = baziCalculator.calculateBazi({
115
+ year: 1990, month: 1, day: 1,
116
+ timeIndex: 0,
117
+ gender: 'male',
118
+ useTrueSolarTime: true,
119
+ birthHour: 0, birthMinute: 30,
120
+ birthLongitude: 116.4, // 北京经度
121
+ });
122
+ ```
47
123
 
48
- // Liuyao
124
+ ### 占卜算法
125
+
126
+ ```typescript
127
+ // 六爻(默认当前时间起卦)
49
128
  import { generateLiuyao } from 'mingyu-core/divination/liuyao';
50
- const liuyaoData = generateLiuyao();
129
+ const liuyao = generateLiuyao();
130
+ // 也可指定时间: generateLiuyao(new Date('2025-01-01T10:00:00'))
51
131
 
52
- // Liuren
132
+ // 梅花易数(数字起卦)
133
+ import { generateMeihua } from 'mingyu-core/divination/meihua';
134
+ const meihua = generateMeihua({ method: 'number', number: 123 });
135
+
136
+ // 奇门遁甲
137
+ import { generateQimen } from 'mingyu-core/divination/qimen';
138
+ const qimen = generateQimen(); // 当前时间
139
+
140
+ // 大六壬
53
141
  import { generateLiuren } from 'mingyu-core/divination/liuren';
54
- const liurenData = generateLiuren();
142
+ const liuren = generateLiuren();
143
+
144
+ // 小六壬
145
+ import { generateXiaoliuren } from 'mingyu-core/divination/xiaoliuren';
146
+ const xiaoliuren = generateXiaoliuren({ method: 'time' });
147
+ ```
148
+
149
+ ### 八字增强分析(从 vibebazi 整合)
55
150
 
56
- // Calendar utilities
151
+ ```typescript
152
+ import {
153
+ analyzeTenGodStructure, // 十神结构分布
154
+ analyzeStemRootProfile, // 透干通根
155
+ analyzeRelationStructure, // 地支关系(三合/三会/六合/六冲/六害/三刑/相破)
156
+ calculateMingGua, // 命卦(东四命/西四命)
157
+ buildLuckDirectionProfile, // 大运顺逆方向
158
+ } from 'mingyu-core/bazi';
159
+
160
+ const pillars = [/* 四柱 */];
161
+ const tenGod = analyzeTenGodStructure(pillars, '乙', getTenGod);
162
+ const mingGua = calculateMingGua(1990, 'male'); // { number:1, gua:'坎', eastWest:'东四命' }
163
+ const luckDir = buildLuckDirectionProfile('male', '庚'); // { direction:'顺行' }
164
+ ```
165
+
166
+ ### 历法工具
167
+
168
+ ```typescript
57
169
  import { getDivinationTime, getVoidBranches } from 'mingyu-core/calendar';
58
170
 
59
- // Types
60
- import type { BaziChartResult, QimenData, LiurenData } from 'mingyu-core/types';
171
+ const { ganzhi, timeInfo } = getDivinationTime(); // 当前时间干支
172
+ const voidBranches = getVoidBranches('甲子'); // ['戌',''] 旬空
61
173
  ```
62
174
 
63
- ## Development
175
+ ---
176
+
177
+ ## 主要 API 一览
178
+
179
+ ### 八字(`mingyu-core/bazi`)
180
+
181
+ | 导出 | 类型 | 说明 |
182
+ |------|------|------|
183
+ | `baziCalculator` | 实例 | 调用 `calculateBazi(person)` |
184
+ | `BaziCalculator` | 类 | 同上的类形式 |
185
+ | `analyzeTenGodStructure` | 函数 | 十神分布与家族聚合 |
186
+ | `analyzeStemRootProfile` | 函数 | 透干通根分析 |
187
+ | `analyzeExposedStemProfile` | 函数 | 透干综合画像 |
188
+ | `analyzeRelationStructure` | 函数 | 地支关系完整评估 |
189
+ | `analyzeKongWangProfile` | 函数 | 空亡全分析 |
190
+ | `analyzeTombStorage` | 函数 | 辰戌丑未墓库分析 |
191
+ | `analyzeLifeStageProfile` | 函数 | 十二长生分布 |
192
+ | `analyzeTenGodLifeStageProfile` | 函数 | 十神十二长生分析 |
193
+ | `analyzeUsefulGodPlacement` | 函数 | 用神落点分析 |
194
+ | `analyzeNayinProfile` | 函数 | 纳音五行分析 |
195
+ | `analyzeMonthQiProfile` | 函数 | 月令气数(旺相休囚死) |
196
+ | `analyzeMatterFocusProfile` | 函数 | 事项宫位分析 |
197
+ | `calculateMingGua` | 函数 | 命卦计算 |
198
+ | `calculateXiaoYunProfile` | 函数 | 小运(童限逐年) |
199
+ | `buildLuckDirectionProfile` | 函数 | 大运顺逆方向 |
200
+
201
+ ### 占卜(`mingyu-core/divination/*`)
202
+
203
+ | 导出 | 说明 |
204
+ |------|------|
205
+ | `generateLiuyao(date?)` | 六爻起卦 |
206
+ | `generateMeihua(settings?)` | 梅花易数起卦 |
207
+ | `generateQimen(date?, method?)` | 奇门遁甲排盘 |
208
+ | `generateLiuren(date?)` | 大六壬排盘 |
209
+ | `generateXiaoliuren(params?)` | 小六壬起课 |
210
+ | `generateAlmanacSelection(params)` | 黄历择日 |
211
+ | `drawRandomSign()` | 三山国王灵签 |
212
+ | `drawLenormandSpread(spreadType?)` | 雷诺曼牌阵 |
213
+ | `generateAstrolabe(input)` | 西洋星盘 |
214
+
215
+ ### 类型(`mingyu-core/types`)
216
+
217
+ 所有返回值类型均从 `mingyu-core/types` 导出,包括 `BaziChartResult`、`LiuyaoData`、`QimenData`、`LiurenData`、`MeihuaData` 等。详细字段说明见 [docs/API.md](docs/API.md)。
218
+
219
+ ---
220
+
221
+ ## 完整 API 文档
222
+
223
+ 各模块的详细参数、返回值字段、数据结构说明,请参阅:
224
+
225
+ - 📖 **[API 参考文档](docs/API.md)** — 所有函数签名与主要类型字段
226
+ - 📖 **[算法审查记录](docs/AUDIT.md)** — 发布前审查发现并修正的问题
227
+
228
+ ---
229
+
230
+ ## 开发
64
231
 
65
232
  ```bash
66
- git clone https://github.com/Brhiza/mingyu
67
- cd mingyu/packages/core
68
- npm install
69
- npm run build
233
+ git clone https://github.com/Brhiza/mingyu.git
234
+ cd mingyu
235
+ npm install -g pnpm
236
+ pnpm install
237
+
238
+ # 构建 core 包
239
+ pnpm --filter mingyu-core build
240
+
241
+ # 运行测试(692 个测试)
242
+ pnpm test
243
+
244
+ # 仅运行 core 包测试
245
+ pnpm --filter mingyu-core test
70
246
  ```
71
247
 
248
+ 项目以 pnpm workspace 形式维护,`packages/core/` 为本包源码,`src/` 为应用层。
249
+
250
+ ---
251
+
252
+ ## 算法审查
253
+
254
+ 本包在发布前经过逐文件地毯式审查,对照传统古籍核对算法正确性。审查发现并修正的问题记录在 [docs/AUDIT.md](docs/AUDIT.md),包括:
255
+
256
+ - 天干相冲缺戊己的数据 Bug
257
+ - 命卦公式的错误重写
258
+ - 小运算法的错误移植
259
+ - 十神评分口径与 vibebazi 对齐
260
+ - 约 40 处重复数据统一到共享层
261
+
262
+ ---
263
+
264
+ ## 相关项目
265
+
266
+ - **[mingyu](https://github.com/Brhiza/mingyu)** — 本包的宿主项目,含 React 前端、MCP Server、公开 API
267
+ - **[vibebazi](https://github.com/Brhiza/vibebazi)** — 八字增强分析模块的来源
268
+
269
+ ---
270
+
72
271
  ## License
73
272
 
74
- MIT
75
-
76
- ## References
77
-
78
- This package implements algorithms based on classical Chinese texts including:
79
- - 《渊海子平》(Yuanhai Ziping) - Bazi system
80
- - 《三命通会》(Sanming Tonghui) - Bazi/Shensha
81
- - 《穷通宝鉴》(Qiong Tong Bao Jian) - Climate rules
82
- - 《卜筮正宗》(Bu Shi Zheng Zong) - Liuyao
83
- - 《增删卜易》(Zeng Shan Bu Yi) - Liuyao
84
- - 《梅花易数》(Meihua Yishu) - Plum Blossom
85
- - 《烟波钓叟歌》(Yan Bo Diao Sou Ge) - Qimen Dunjia
86
- - 《遁甲演义》(Dunjia Yanyi) - Qimen Dunjia
87
- - 《大六壬大全》(Da Liuren Daquan) - Liuren
88
- - 《大六壬指南》(Da Liuren Zhinan) - Liuren
89
- - 《协纪辨方书》(Xieji Bianfang Shu) - Almanac
90
- - 《紫微斗数全书》(Ziwei Doushu Quanshu) - Ziwei
273
+ [MIT](LICENSE)
274
+
275
+ ## 免责
276
+
277
+ 命理术数仅供参考娱乐,本库不对任何基于输出做出的决策负责。
@@ -100,7 +100,7 @@ export declare function generateLiuyao(customDate?: Date): {
100
100
  isDayBreak: boolean;
101
101
  isMonthBreak: boolean;
102
102
  isHiddenMove: boolean;
103
- seasonState: "" | "" | "" | "" | "休" | "";
103
+ seasonState: "" | "" | "" | "" | "休" | "";
104
104
  changeDirection: "化进神" | "化退神";
105
105
  changeRelation: "回头生" | "回头克" | "回头冲" | "化空" | "比和";
106
106
  isSanxing: boolean;
@@ -17,7 +17,7 @@ export declare function drawSingleCard(): {
17
17
  timestamp: number;
18
18
  };
19
19
  export declare function drawSpreadCards(spreadType: keyof typeof tarotSpreads): {
20
- spreadType: "year" | "career" | "single" | "three" | "decision" | "love" | "celtic" | "chakra" | "mindBodySpirit" | "horseshoe";
20
+ spreadType: "year" | "single" | "three" | "love" | "career" | "decision" | "celtic" | "chakra" | "mindBodySpirit" | "horseshoe";
21
21
  spreadName: string;
22
22
  cards: any[];
23
23
  timestamp: number;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "mingyu-core",
3
- "version": "0.1.0",
3
+ "version": "0.1.1",
4
4
  "description": "Mingyu core algorithms: traditional Chinese metaphysics (八字Bazi, 紫微斗数Ziwei, 奇门遁甲Qimen, 六爻Liuyao, 六壬Liuren, 梅花易数Meihua, and more)",
5
5
  "type": "module",
6
6
  "main": "./dist/index.js",