kinwuzhao 1.0.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/README.zh-CN.md +303 -0
- package/dist/index.cjs +692 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +201 -0
- package/dist/index.d.ts +201 -0
- package/dist/index.js +654 -0
- package/dist/index.js.map +1 -0
- package/package.json +57 -0
package/README.zh-CN.md
ADDED
|
@@ -0,0 +1,303 @@
|
|
|
1
|
+
# **Kinwuzhao (堅五兆) - TypeScript实现**
|
|
2
|
+
|
|
3
|
+
[](https://www.npmjs.com/package/kinwuzhao)
|
|
4
|
+
[](LICENSE)
|
|
5
|
+
|
|
6
|
+
五兆占卜排盘系统的TypeScript实现。
|
|
7
|
+
|
|
8
|
+
## 📖 简介
|
|
9
|
+
|
|
10
|
+
五兆是汉语词汇中记载的古代占卜方法,其核心定义源自《旧唐书·太宗纪上》。该方法在唐宋文献中多次出现,如宋代梅尧臣《江南杂感》诗及赵彦卫《云麓漫钞》均提及其实践方式,敦煌出土文献则保存了唐代五兆卜法的具体操作流程与卦象解析文本。
|
|
11
|
+
|
|
12
|
+
本项目将原Python实现转换为TypeScript库,提供现代化的API和完整的类型支持。
|
|
13
|
+
|
|
14
|
+
## ✨ 特性
|
|
15
|
+
|
|
16
|
+
- 🎯 **完整功能**:支持五兆随机分配和干支起盘两种模式
|
|
17
|
+
- 📅 **节气计算**:精确计算二十四节气
|
|
18
|
+
- 🌟 **干支转换**:准确的公历到干支转换
|
|
19
|
+
- 📦 **TypeScript**:完整的类型定义
|
|
20
|
+
- ✅ **测试覆盖**:完善的单元测试
|
|
21
|
+
- 🚀 **现代化**:使用ESM模块系统
|
|
22
|
+
|
|
23
|
+
## 📦 安装
|
|
24
|
+
|
|
25
|
+
使用pnpm(推荐):
|
|
26
|
+
|
|
27
|
+
```bash
|
|
28
|
+
pnpm add kinwuzhao
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
使用npm:
|
|
32
|
+
|
|
33
|
+
```bash
|
|
34
|
+
npm install kinwuzhao
|
|
35
|
+
```
|
|
36
|
+
|
|
37
|
+
使用yarn:
|
|
38
|
+
|
|
39
|
+
```bash
|
|
40
|
+
yarn add kinwuzhao
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
## 🚀 快速开始
|
|
44
|
+
|
|
45
|
+
### 基本用法
|
|
46
|
+
|
|
47
|
+
```typescript
|
|
48
|
+
import { ganZhi, findCurrentJieQi, fiveZhaoPaiPan } from 'kinwuzhao';
|
|
49
|
+
|
|
50
|
+
// 1. 获取干支
|
|
51
|
+
const gz = ganZhi(2025, 6, 27, 11, 24);
|
|
52
|
+
console.log(gz);
|
|
53
|
+
// { year: '乙巳', month: '壬午', day: '甲子', hour: '庚午', minute: '己卯' }
|
|
54
|
+
|
|
55
|
+
// 2. 获取当前节气
|
|
56
|
+
const jq = findCurrentJieQi(2025, 6, 27, 11, 24);
|
|
57
|
+
console.log(jq); // '夏至'
|
|
58
|
+
|
|
59
|
+
// 3. 五兆排盘(随机分配模式)
|
|
60
|
+
const result = fiveZhaoPaiPan(0, jq, '五', gz.day, gz.hour);
|
|
61
|
+
console.log(result);
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
### 干支起盘模式
|
|
65
|
+
|
|
66
|
+
```typescript
|
|
67
|
+
import { ganZhi, findCurrentJieQi, ganzhiPaiPan } from 'kinwuzhao';
|
|
68
|
+
|
|
69
|
+
// 获取干支
|
|
70
|
+
const gz = ganZhi(2025, 6, 27, 11, 24);
|
|
71
|
+
|
|
72
|
+
// 获取节气
|
|
73
|
+
const jq = findCurrentJieQi(2025, 6, 27, 11, 24);
|
|
74
|
+
|
|
75
|
+
// 干支起盘
|
|
76
|
+
const result = ganzhiPaiPan(gz, 0, jq, '五');
|
|
77
|
+
console.log(result);
|
|
78
|
+
|
|
79
|
+
// 输出包含六个宫位的信息
|
|
80
|
+
console.log(result.兆); // 巽宫(兆)
|
|
81
|
+
console.log(result.木鄉); // 震宫
|
|
82
|
+
console.log(result.火鄉); // 离宫
|
|
83
|
+
console.log(result.土鄉); // 中宫
|
|
84
|
+
console.log(result.金鄉); // 兑宫
|
|
85
|
+
console.log(result.水鄉); // 坎宫
|
|
86
|
+
```
|
|
87
|
+
|
|
88
|
+
### 节气查询
|
|
89
|
+
|
|
90
|
+
```typescript
|
|
91
|
+
import { findJieQiDate, findSeason, distanceToJieQi } from 'kinwuzhao';
|
|
92
|
+
|
|
93
|
+
// 查找2025年春分的日期
|
|
94
|
+
const chunfenDate = findJieQiDate(2025, '春分');
|
|
95
|
+
console.log(chunfenDate); // 2025年3月20日
|
|
96
|
+
|
|
97
|
+
// 查找节气对应的季节
|
|
98
|
+
const season = findSeason('春分');
|
|
99
|
+
console.log(season); // '春'
|
|
100
|
+
|
|
101
|
+
// 计算距离节气的天数
|
|
102
|
+
const distance = distanceToJieQi(2025, 6, 27, '夏至');
|
|
103
|
+
console.log(distance); // 距离夏至的天数
|
|
104
|
+
```
|
|
105
|
+
|
|
106
|
+
## 📚 API文档
|
|
107
|
+
|
|
108
|
+
### 干支计算
|
|
109
|
+
|
|
110
|
+
#### `ganZhi(year, month, day, hour, minute)`
|
|
111
|
+
|
|
112
|
+
将公历日期转换为干支。
|
|
113
|
+
|
|
114
|
+
**参数:**
|
|
115
|
+
- `year`: 年份
|
|
116
|
+
- `month`: 月份 (1-12)
|
|
117
|
+
- `day`: 日期
|
|
118
|
+
- `hour`: 小时 (0-23)
|
|
119
|
+
- `minute`: 分钟 (0-59)
|
|
120
|
+
|
|
121
|
+
**返回:** `GanZhiResult`
|
|
122
|
+
```typescript
|
|
123
|
+
{
|
|
124
|
+
year: string; // 年干支
|
|
125
|
+
month: string; // 月干支
|
|
126
|
+
day: string; // 日干支
|
|
127
|
+
hour: string; // 时干支
|
|
128
|
+
minute: string; // 分干支
|
|
129
|
+
}
|
|
130
|
+
```
|
|
131
|
+
|
|
132
|
+
### 节气计算
|
|
133
|
+
|
|
134
|
+
#### `findCurrentJieQi(year, month, day, hour, minute)`
|
|
135
|
+
|
|
136
|
+
查找当前时间所处的节气。
|
|
137
|
+
|
|
138
|
+
**返回:** 节气名称(如"春分"、"夏至"等)
|
|
139
|
+
|
|
140
|
+
#### `findJieQiDate(year, jieqiName)`
|
|
141
|
+
|
|
142
|
+
查找指定年份某个节气的日期。
|
|
143
|
+
|
|
144
|
+
**返回:** `Date` 或 `null`
|
|
145
|
+
|
|
146
|
+
#### `findSeason(jieqi)`
|
|
147
|
+
|
|
148
|
+
根据节气查找对应的季节。
|
|
149
|
+
|
|
150
|
+
**返回:** "春"、"夏"、"秋"或"冬"
|
|
151
|
+
|
|
152
|
+
### 五兆排盘
|
|
153
|
+
|
|
154
|
+
#### `fiveZhaoPaiPan(num, jq, cm, gz1, gz2, liurenData?)`
|
|
155
|
+
|
|
156
|
+
五兆随机分配排盘。
|
|
157
|
+
|
|
158
|
+
**参数:**
|
|
159
|
+
- `num`: 起卦数字
|
|
160
|
+
- `jq`: 节气
|
|
161
|
+
- `cm`: 农历月
|
|
162
|
+
- `gz1`: 干支1(用于配六兽)
|
|
163
|
+
- `gz2`: 干支2(用于孤虚)
|
|
164
|
+
- `liurenData`: 可选的六壬数据
|
|
165
|
+
|
|
166
|
+
**返回:** `WuZhaoPaiPanResult`
|
|
167
|
+
|
|
168
|
+
#### `ganzhiPaiPan(gzList, num, jq, cm, liurenData?)`
|
|
169
|
+
|
|
170
|
+
干支起盘模式。
|
|
171
|
+
|
|
172
|
+
**参数:**
|
|
173
|
+
- `gzList`: 干支列表(由`ganZhi()`返回)
|
|
174
|
+
- `num`: 额外数字
|
|
175
|
+
- `jq`: 节气
|
|
176
|
+
- `cm`: 农历月
|
|
177
|
+
- `liurenData`: 可选的六壬数据
|
|
178
|
+
|
|
179
|
+
**返回:** `WuZhaoPaiPanResult`
|
|
180
|
+
|
|
181
|
+
### 排盘结果结构
|
|
182
|
+
|
|
183
|
+
```typescript
|
|
184
|
+
interface WuZhaoPaiPanResult {
|
|
185
|
+
兆?: GongWeiInfo; // 巽宫
|
|
186
|
+
木鄉?: GongWeiInfo; // 震宫
|
|
187
|
+
火鄉?: GongWeiInfo; // 离宫
|
|
188
|
+
土鄉?: GongWeiInfo; // 中宫
|
|
189
|
+
金鄉?: GongWeiInfo; // 兑宫
|
|
190
|
+
水鄉?: GongWeiInfo; // 坎宫
|
|
191
|
+
錯誤?: string; // 错误信息
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
interface GongWeiInfo {
|
|
195
|
+
宮位: string; // 宫位名称
|
|
196
|
+
宮位1: string; // 宫位八卦
|
|
197
|
+
旺相: string; // 旺相状态
|
|
198
|
+
數字: number; // 数字(1-5)
|
|
199
|
+
五行: string; // 五行
|
|
200
|
+
六獸: string; // 六兽
|
|
201
|
+
六獸死: string; // 六兽死
|
|
202
|
+
六獸害: string; // 六兽害
|
|
203
|
+
六親: string; // 六亲
|
|
204
|
+
孤: string; // 孤
|
|
205
|
+
虛: string; // 虚
|
|
206
|
+
關: string; // 关
|
|
207
|
+
籥: string; // 钥
|
|
208
|
+
將軍: string; // 将军
|
|
209
|
+
}
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
## 🧪 开发
|
|
213
|
+
|
|
214
|
+
### 安装依赖
|
|
215
|
+
|
|
216
|
+
```bash
|
|
217
|
+
pnpm install
|
|
218
|
+
```
|
|
219
|
+
|
|
220
|
+
### 运行测试
|
|
221
|
+
|
|
222
|
+
```bash
|
|
223
|
+
pnpm test
|
|
224
|
+
```
|
|
225
|
+
|
|
226
|
+
### 查看测试覆盖率
|
|
227
|
+
|
|
228
|
+
```bash
|
|
229
|
+
pnpm test:coverage
|
|
230
|
+
```
|
|
231
|
+
|
|
232
|
+
### 运行测试UI
|
|
233
|
+
|
|
234
|
+
```bash
|
|
235
|
+
pnpm test:ui
|
|
236
|
+
```
|
|
237
|
+
|
|
238
|
+
### 构建
|
|
239
|
+
|
|
240
|
+
```bash
|
|
241
|
+
pnpm build
|
|
242
|
+
```
|
|
243
|
+
|
|
244
|
+
### 类型检查
|
|
245
|
+
|
|
246
|
+
```bash
|
|
247
|
+
pnpm type-check
|
|
248
|
+
```
|
|
249
|
+
|
|
250
|
+
### 代码格式化
|
|
251
|
+
|
|
252
|
+
```bash
|
|
253
|
+
pnpm format
|
|
254
|
+
```
|
|
255
|
+
|
|
256
|
+
### Linting
|
|
257
|
+
|
|
258
|
+
```bash
|
|
259
|
+
pnpm lint
|
|
260
|
+
```
|
|
261
|
+
|
|
262
|
+
## 📝 示例
|
|
263
|
+
|
|
264
|
+
查看 `examples` 目录获取更多示例:
|
|
265
|
+
|
|
266
|
+
- `examples/basic.ts` - 基本用法
|
|
267
|
+
- `examples/advanced.ts` - 高级用法
|
|
268
|
+
- `examples/complete-output.mjs` - 完整输出示例(可直接运行)
|
|
269
|
+
|
|
270
|
+
### 运行完整输出示例
|
|
271
|
+
|
|
272
|
+
```bash
|
|
273
|
+
node examples/complete-output.mjs
|
|
274
|
+
```
|
|
275
|
+
|
|
276
|
+
这将展示:
|
|
277
|
+
- ✅ 详细的干支计算过程
|
|
278
|
+
- ✅ 节气信息
|
|
279
|
+
- ✅ 完整的排盘结果(六个宫位)
|
|
280
|
+
- ✅ 格式化的盘面显示
|
|
281
|
+
- ✅ 断卦要点分析
|
|
282
|
+
- ✅ 随机排盘演示
|
|
283
|
+
- ✅ 多次排盘对比
|
|
284
|
+
- ✅ 四季节气对比
|
|
285
|
+
|
|
286
|
+
## 🤝 贡献
|
|
287
|
+
|
|
288
|
+
欢迎提交Issue和Pull Request!
|
|
289
|
+
|
|
290
|
+
## 📄 许可证
|
|
291
|
+
|
|
292
|
+
MIT License
|
|
293
|
+
|
|
294
|
+
## 🙏 致谢
|
|
295
|
+
|
|
296
|
+
本项目基于原Python实现转换而来,感谢原作者的贡献。
|
|
297
|
+
|
|
298
|
+
## 📚 参考文献
|
|
299
|
+
|
|
300
|
+
- 《旧唐书·太宗纪上》
|
|
301
|
+
- 宋代梅尧臣《江南杂感》
|
|
302
|
+
- 赵彦卫《云麓漫钞》
|
|
303
|
+
- 敦煌文献 P.2859《五兆要诀略》
|