ziwei-cli 1.1.2 → 1.1.3
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/lib/commands/palace.js +18 -37
- package/package.json +1 -1
package/lib/commands/palace.js
CHANGED
|
@@ -16,28 +16,13 @@ function buildQueryDate(year, month = 1, day = 1) {
|
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
/**
|
|
19
|
-
*
|
|
19
|
+
* 获取指定层级的宫位及三方四正(统一走 horoscope 接口)
|
|
20
20
|
*/
|
|
21
|
-
function getScopedPalaceAndSurrounded(
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
return { targetPalace, surroundedPalaces, scopeData: {} };
|
|
27
|
-
} else {
|
|
28
|
-
// 运限层从 horoscope 获取
|
|
29
|
-
const horoscope = astrolabe.horoscope(queryDate);
|
|
30
|
-
const scopeData = horoscope[scope];
|
|
31
|
-
|
|
32
|
-
if (!scopeData) {
|
|
33
|
-
throw new Error(`无效的运限范围: ${scope}`);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
const targetPalace = horoscope.palace(palaceName, scope);
|
|
37
|
-
const surroundedPalaces = horoscope.surroundPalaces(palaceName, scope);
|
|
38
|
-
|
|
39
|
-
return { targetPalace, surroundedPalaces, scopeData };
|
|
40
|
-
}
|
|
21
|
+
function getScopedPalaceAndSurrounded(horoscope, palaceName, scope) {
|
|
22
|
+
const scopeData = horoscope[scope] || {};
|
|
23
|
+
const targetPalace = horoscope.palace(palaceName, scope);
|
|
24
|
+
const surroundedPalaces = horoscope.surroundPalaces(palaceName, scope);
|
|
25
|
+
return { targetPalace, surroundedPalaces, scopeData };
|
|
41
26
|
}
|
|
42
27
|
|
|
43
28
|
/**
|
|
@@ -87,18 +72,20 @@ export async function executePalace(options) {
|
|
|
87
72
|
is_leap: leap || false
|
|
88
73
|
});
|
|
89
74
|
|
|
90
|
-
//
|
|
91
|
-
|
|
92
|
-
const
|
|
93
|
-
|
|
94
|
-
|
|
75
|
+
// 归一化宫位名称:iztro 内部除"命宫"外均不带"宫"字
|
|
76
|
+
const base = palace.replace(/宫$/, '');
|
|
77
|
+
const targetPalaceName = base === '命' ? '命宫' : base;
|
|
78
|
+
|
|
79
|
+
// 构建查询日期(origin 用今天的日期,不影响本命数据)
|
|
80
|
+
const queryDate = scope !== 'origin'
|
|
81
|
+
? buildQueryDate(year, month || 1, day || 1)
|
|
82
|
+
: new Date().toISOString().slice(0, 10);
|
|
95
83
|
|
|
96
|
-
//
|
|
97
|
-
const
|
|
84
|
+
// 统一通过 horoscope 接口查询所有层级
|
|
85
|
+
const horoscope = astrolabe.horoscope(queryDate);
|
|
98
86
|
|
|
99
|
-
// 获取目标宫位和三方四正
|
|
100
87
|
const { targetPalace, surroundedPalaces, scopeData } = getScopedPalaceAndSurrounded(
|
|
101
|
-
|
|
88
|
+
horoscope, targetPalaceName, scope
|
|
102
89
|
);
|
|
103
90
|
|
|
104
91
|
if (!targetPalace) {
|
|
@@ -109,13 +96,7 @@ export async function executePalace(options) {
|
|
|
109
96
|
}
|
|
110
97
|
|
|
111
98
|
// 检测格局
|
|
112
|
-
|
|
113
|
-
if (scope === 'origin') {
|
|
114
|
-
patterns = detectPatterns(astrolabe);
|
|
115
|
-
} else {
|
|
116
|
-
const horoscope = astrolabe.horoscope(queryDate);
|
|
117
|
-
patterns = detectPatterns(horoscope, scope);
|
|
118
|
-
}
|
|
99
|
+
const patterns = detectPatterns(horoscope, scope);
|
|
119
100
|
|
|
120
101
|
// 构建结果
|
|
121
102
|
const result = {
|