bazi-terms 0.1.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/LICENSE +21 -0
- package/README.md +96 -0
- package/dist/index.cjs +626 -0
- package/dist/index.cjs.map +1 -0
- package/dist/index.d.cts +252 -0
- package/dist/index.d.ts +252 -0
- package/dist/index.js +549 -0
- package/dist/index.js.map +1 -0
- package/package.json +53 -0
package/dist/index.d.ts
ADDED
|
@@ -0,0 +1,252 @@
|
|
|
1
|
+
/** Supported output languages. */
|
|
2
|
+
type Lang = 'zh' | 'en';
|
|
3
|
+
/** A single bilingual terminology entry. */
|
|
4
|
+
interface Term {
|
|
5
|
+
/** Stable machine-readable identifier (camelCase pinyin or English). */
|
|
6
|
+
key: string;
|
|
7
|
+
/** Chinese name. */
|
|
8
|
+
zh: string;
|
|
9
|
+
/** English name. */
|
|
10
|
+
en: string;
|
|
11
|
+
/** Pinyin with tone marks (optional). */
|
|
12
|
+
pinyin?: string;
|
|
13
|
+
/** One-sentence English definition — what a blog author can copy-paste. */
|
|
14
|
+
definition?: string;
|
|
15
|
+
}
|
|
16
|
+
type StemKey = 'jia' | 'yi' | 'bing' | 'ding' | 'wu' | 'ji' | 'geng' | 'xin' | 'ren' | 'gui';
|
|
17
|
+
type BranchKey = 'zi' | 'chou' | 'yin' | 'mao' | 'chen' | 'si' | 'wuHorse' | 'wei' | 'shen' | 'you' | 'xu' | 'hai';
|
|
18
|
+
type ElementKey = 'wood' | 'fire' | 'earth' | 'metal' | 'water';
|
|
19
|
+
type Polarity = 'yang' | 'yin';
|
|
20
|
+
type TenGodKey = 'biJian' | 'jieCai' | 'shiShen' | 'shangGuan' | 'pianCai' | 'zhengCai' | 'qiSha' | 'zhengGuan' | 'pianYin' | 'zhengYin' | 'dayMaster';
|
|
21
|
+
type GrowthStageKey = 'birth' | 'bathing' | 'crowning' | 'officiating' | 'peak' | 'decline' | 'illness' | 'death' | 'tomb' | 'extinction' | 'gestation' | 'nurturing';
|
|
22
|
+
type InteractionTypeKey = 'stemCombination' | 'liuHe' | 'sanHe' | 'sanHui' | 'liuChong' | 'xiangXing' | 'xiangHai' | 'xiangPo';
|
|
23
|
+
/** Stem term enriched with element and polarity. */
|
|
24
|
+
interface StemTerm extends Term {
|
|
25
|
+
key: StemKey;
|
|
26
|
+
element: ElementKey;
|
|
27
|
+
polarity: Polarity;
|
|
28
|
+
}
|
|
29
|
+
/** Branch term enriched with zodiac animal, element and clock hours. */
|
|
30
|
+
interface BranchTerm extends Term {
|
|
31
|
+
key: BranchKey;
|
|
32
|
+
zodiacEn: string;
|
|
33
|
+
zodiacZh: string;
|
|
34
|
+
element: ElementKey;
|
|
35
|
+
/** Representative clock hour range, e.g. "23:00-01:00". */
|
|
36
|
+
hours: string;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* The Ten Heavenly Stems (十天干).
|
|
41
|
+
* Order matters: index is used for combination/clash arithmetic.
|
|
42
|
+
*/
|
|
43
|
+
declare const STEMS: readonly StemTerm[];
|
|
44
|
+
/** Lookup: Chinese character → stem term. */
|
|
45
|
+
declare const STEM_BY_CHAR: Readonly<Record<string, StemTerm>>;
|
|
46
|
+
/** Lookup: key → stem term. */
|
|
47
|
+
declare const STEM_BY_KEY: Readonly<Record<string, StemTerm>>;
|
|
48
|
+
/**
|
|
49
|
+
* Resolve a Heavenly Stem from a Chinese character.
|
|
50
|
+
* Returns undefined for unknown characters instead of throwing,
|
|
51
|
+
* so callers can render raw data defensively.
|
|
52
|
+
*/
|
|
53
|
+
declare function stemByChar(char: string): StemTerm | undefined;
|
|
54
|
+
|
|
55
|
+
/**
|
|
56
|
+
* The Twelve Earthly Branches (十二地支).
|
|
57
|
+
* Order matters: index is used for clash/combination arithmetic.
|
|
58
|
+
* Note: the key for 午 (Horse) is 'wuHorse' to avoid colliding with stem 戊 (wu).
|
|
59
|
+
*/
|
|
60
|
+
declare const BRANCHES: readonly BranchTerm[];
|
|
61
|
+
/** Lookup: Chinese character → branch term. */
|
|
62
|
+
declare const BRANCH_BY_CHAR: Readonly<Record<string, BranchTerm>>;
|
|
63
|
+
/** Lookup: key → branch term. */
|
|
64
|
+
declare const BRANCH_BY_KEY: Readonly<Record<string, BranchTerm>>;
|
|
65
|
+
/** Resolve an Earthly Branch from a Chinese character. */
|
|
66
|
+
declare function branchByChar(char: string): BranchTerm | undefined;
|
|
67
|
+
|
|
68
|
+
interface ElementTerm extends Term {
|
|
69
|
+
key: ElementKey;
|
|
70
|
+
}
|
|
71
|
+
/** The Five Elements (五行). */
|
|
72
|
+
declare const ELEMENTS: readonly ElementTerm[];
|
|
73
|
+
/** Lookup: Chinese character → element term. */
|
|
74
|
+
declare const ELEMENT_BY_CHAR: Readonly<Record<string, ElementTerm>>;
|
|
75
|
+
/** Lookup: key → element term. */
|
|
76
|
+
declare const ELEMENT_BY_KEY: Readonly<Record<string, ElementTerm>>;
|
|
77
|
+
/** Resolve a Five Element from a Chinese character or an English key. */
|
|
78
|
+
declare function elementOf(input: string): ElementTerm | undefined;
|
|
79
|
+
/**
|
|
80
|
+
* The generating (生) and controlling (克) cycles, as key pairs.
|
|
81
|
+
* generating: Wood→Fire→Earth→Metal→Water→Wood
|
|
82
|
+
* controlling: Wood→Earth→Water→Fire→Metal→Wood
|
|
83
|
+
*/
|
|
84
|
+
declare const ELEMENT_CYCLES: {
|
|
85
|
+
readonly generating: [ElementKey, ElementKey][];
|
|
86
|
+
readonly controlling: [ElementKey, ElementKey][];
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
interface TenGodTerm extends Term {
|
|
90
|
+
key: TenGodKey;
|
|
91
|
+
}
|
|
92
|
+
/**
|
|
93
|
+
* The Ten Gods (十神) — relationship labels between each stem
|
|
94
|
+
* and the Day Master, based on element and polarity.
|
|
95
|
+
* Plus the Day Master itself, which engines emit as 日主 / 元男 / 元女.
|
|
96
|
+
*/
|
|
97
|
+
declare const TEN_GODS: readonly TenGodTerm[];
|
|
98
|
+
/** Lookup: key → ten-god term. */
|
|
99
|
+
declare const TEN_GOD_BY_KEY: Readonly<Record<string, TenGodTerm>>;
|
|
100
|
+
/** Resolve a Ten God from its Chinese label (aliases included). */
|
|
101
|
+
declare function tenGodByZh(zh: string): TenGodTerm | undefined;
|
|
102
|
+
|
|
103
|
+
interface GrowthStageTerm extends Term {
|
|
104
|
+
key: GrowthStageKey;
|
|
105
|
+
}
|
|
106
|
+
/**
|
|
107
|
+
* The Twelve Growth Stages (十二长生) — the lifecycle of an element
|
|
108
|
+
* across the twelve branches: birth → bathing → … → extinction → gestation → nurturing.
|
|
109
|
+
*/
|
|
110
|
+
declare const GROWTH_STAGES: readonly GrowthStageTerm[];
|
|
111
|
+
/** Lookup: key → growth-stage term. */
|
|
112
|
+
declare const GROWTH_STAGE_BY_KEY: Readonly<Record<string, GrowthStageTerm>>;
|
|
113
|
+
/** Lookup: Chinese label → growth-stage term. */
|
|
114
|
+
declare const GROWTH_STAGE_BY_ZH: Readonly<Record<string, GrowthStageTerm>>;
|
|
115
|
+
/** Resolve a growth stage from its Chinese label. */
|
|
116
|
+
declare function growthStageByZh(zh: string): GrowthStageTerm | undefined;
|
|
117
|
+
|
|
118
|
+
/**
|
|
119
|
+
* Common Shen Sha (神煞) — symbolic stars overlaid on the chart.
|
|
120
|
+
* Coverage: the stars emitted by common community Bazi engines’ golden
|
|
121
|
+
* samples, plus the most frequently referenced traditional stars.
|
|
122
|
+
* Lookup falls back to the raw Chinese name for stars not in this table,
|
|
123
|
+
* so unknown engine output never breaks rendering.
|
|
124
|
+
*/
|
|
125
|
+
declare const SHEN_SHA: readonly Term[];
|
|
126
|
+
/** Lookup: Chinese name → shen sha term. */
|
|
127
|
+
declare const SHEN_SHA_BY_ZH: Readonly<Record<string, Term>>;
|
|
128
|
+
/** Lookup: key → shen sha term. */
|
|
129
|
+
declare const SHEN_SHA_BY_KEY: Readonly<Record<string, Term>>;
|
|
130
|
+
/**
|
|
131
|
+
* Resolve a Shen Sha star from its Chinese name.
|
|
132
|
+
* Unknown stars return undefined — render the raw name instead of dropping data.
|
|
133
|
+
*/
|
|
134
|
+
declare function shenShaByZh(zh: string): Term | undefined;
|
|
135
|
+
|
|
136
|
+
interface NaYinTerm extends Term {
|
|
137
|
+
/** The two sexagenary pairs this melody covers, e.g. ['甲子', '乙丑']. */
|
|
138
|
+
pairs: [string, string];
|
|
139
|
+
}
|
|
140
|
+
/**
|
|
141
|
+
* The Sixty Jiazi Na Yin (六十甲子纳音) — 30 melodic elements,
|
|
142
|
+
* each covering two consecutive sexagenary cycle entries.
|
|
143
|
+
*/
|
|
144
|
+
declare const NA_YIN: readonly NaYinTerm[];
|
|
145
|
+
/** Lookup: Na Yin Chinese name → term. */
|
|
146
|
+
declare const NA_YIN_BY_ZH: Readonly<Record<string, NaYinTerm>>;
|
|
147
|
+
/** Lookup: sexagenary pair (e.g. '甲子') → Na Yin term. */
|
|
148
|
+
declare const NA_YIN_BY_GAN_ZHI: Readonly<Record<string, NaYinTerm>>;
|
|
149
|
+
/** Resolve a Na Yin melody from its Chinese name or a sexagenary pair. */
|
|
150
|
+
declare function naYinOf(input: string): NaYinTerm | undefined;
|
|
151
|
+
|
|
152
|
+
interface InteractionTerm extends Term {
|
|
153
|
+
key: InteractionTypeKey;
|
|
154
|
+
/** English interaction enum value (CLASH, TRINE, …), when one exists. */
|
|
155
|
+
enumCode?: string;
|
|
156
|
+
/** The Chinese verb embedded in description strings like "午子相冲". */
|
|
157
|
+
zhVerb?: string;
|
|
158
|
+
}
|
|
159
|
+
/**
|
|
160
|
+
* Chart interactions (刑冲合会) — the relationships between stems and branches.
|
|
161
|
+
* Each entry carries two optional lookup codes:
|
|
162
|
+
* - an English `type` enum (CLASH, TRINE, …) used by enum-style engines
|
|
163
|
+
* - a Chinese verb embedded in description strings ("午子相冲")
|
|
164
|
+
* The pairing tables below let callers verify or reconstruct a relationship
|
|
165
|
+
* from raw branch characters.
|
|
166
|
+
*/
|
|
167
|
+
declare const INTERACTION_TYPES: readonly InteractionTerm[];
|
|
168
|
+
/** Lookup: key → interaction term. */
|
|
169
|
+
declare const INTERACTION_BY_KEY: Readonly<Record<string, InteractionTerm>>;
|
|
170
|
+
/** Lookup: English interaction enum (CLASH/TRINE/…) → interaction term. */
|
|
171
|
+
declare const INTERACTION_BY_ENUM: Readonly<Record<string, InteractionTerm>>;
|
|
172
|
+
/**
|
|
173
|
+
* Resolve an interaction type from a Chinese description string
|
|
174
|
+
* such as "午子相冲" or "卯子相刑". Returns undefined when no verb matches.
|
|
175
|
+
*/
|
|
176
|
+
declare function interactionFromZh(desc: string): InteractionTerm | undefined;
|
|
177
|
+
/** Resolve an interaction type from an English enum value (CLASH, TRINE, …). */
|
|
178
|
+
declare function interactionFromEnum(type: string): InteractionTerm | undefined;
|
|
179
|
+
/** 天干五合 — the five Heavenly Stem combinations. */
|
|
180
|
+
declare const STEM_COMBINATIONS: readonly (readonly [string, string])[];
|
|
181
|
+
/** 地支六合 — the six branch harmonies. */
|
|
182
|
+
declare const LIU_HE: readonly (readonly [string, string])[];
|
|
183
|
+
/** 地支六冲 — the six branch clashes. */
|
|
184
|
+
declare const LIU_CHONG: readonly (readonly [string, string])[];
|
|
185
|
+
/** 地支三合 — the four three-harmony triads (each resolving to one element). */
|
|
186
|
+
declare const SAN_HE: readonly (readonly [string, string, string])[];
|
|
187
|
+
/** 地支三会 — the four directional (seasonal) triads. */
|
|
188
|
+
declare const SAN_HUI: readonly (readonly [string, string, string])[];
|
|
189
|
+
/** 地支相害 — the six branch harms. */
|
|
190
|
+
declare const XIANG_HAI: readonly (readonly [string, string])[];
|
|
191
|
+
/** 地支相破 — the six branch destructions. */
|
|
192
|
+
declare const XIANG_PO: readonly (readonly [string, string])[];
|
|
193
|
+
/**
|
|
194
|
+
* 地支相刑 — the punishments, grouped by classic type:
|
|
195
|
+
* wuEn (无恩之刑) 寅巳申, shiShi (恃势之刑) 丑戌未,
|
|
196
|
+
* wuLi (无礼之刑) 子卯, and ziXing (自刑) 辰/午/酉/亥 (each with itself).
|
|
197
|
+
*/
|
|
198
|
+
declare const XIANG_XING: {
|
|
199
|
+
readonly wuEn: readonly ["寅", "巳", "申"];
|
|
200
|
+
readonly shiShi: readonly ["丑", "戌", "未"];
|
|
201
|
+
readonly wuLi: readonly ["子", "卯"];
|
|
202
|
+
readonly ziXing: readonly ["辰", "午", "酉", "亥"];
|
|
203
|
+
};
|
|
204
|
+
|
|
205
|
+
/**
|
|
206
|
+
* General chart vocabulary — the structural labels a renderer needs:
|
|
207
|
+
* pillar names, calendar/time terms, cycle concepts and section headers.
|
|
208
|
+
* Category-specific terms (stems, branches, ten gods, shen sha, na yin,
|
|
209
|
+
* growth stages, interactions) live in their own modules; this file holds
|
|
210
|
+
* everything else so a UI can label a chart bilingually end-to-end.
|
|
211
|
+
*/
|
|
212
|
+
declare const GENERAL_TERMS: readonly Term[];
|
|
213
|
+
/** Lookup: key → general term. */
|
|
214
|
+
declare const GENERAL_BY_KEY: Readonly<Record<string, Term>>;
|
|
215
|
+
/** Lookup: Chinese label → general term. */
|
|
216
|
+
declare const GENERAL_BY_ZH: Readonly<Record<string, Term>>;
|
|
217
|
+
/** Resolve a general term by key. */
|
|
218
|
+
declare function generalBy(key: string): Term | undefined;
|
|
219
|
+
/** Resolve a general term by its Chinese label. */
|
|
220
|
+
declare function generalByZh(zh: string): Term | undefined;
|
|
221
|
+
|
|
222
|
+
/** Every term from every category, in a stable order. */
|
|
223
|
+
declare const ALL_TERMS: readonly Term[];
|
|
224
|
+
/** Lookup: unique term key → term. Keys are unique across all categories. */
|
|
225
|
+
declare const TERM_BY_KEY: Readonly<Record<string, Term>>;
|
|
226
|
+
/** Lookup: Chinese label → term (exact match). */
|
|
227
|
+
declare const TERM_BY_ZH: Readonly<Record<string, Term>>;
|
|
228
|
+
/**
|
|
229
|
+
* Translate a term key into the requested language.
|
|
230
|
+
* Returns the key itself when unknown, so rendering never breaks.
|
|
231
|
+
*
|
|
232
|
+
* @example t('dayMaster') // 'Day Master'
|
|
233
|
+
* @example t('dayMaster', 'zh') // '日主'
|
|
234
|
+
*/
|
|
235
|
+
declare function t(key: string, lang?: Lang): string;
|
|
236
|
+
/**
|
|
237
|
+
* Best-effort translation of any raw engine value or term key.
|
|
238
|
+
* Resolution order (exact → fuzzy):
|
|
239
|
+
* 1. term key (e.g. 'qiSha')
|
|
240
|
+
* 2. exact Chinese label (e.g. '天乙贵人', '海中金', '比肩')
|
|
241
|
+
* 3. ten-god alias (e.g. '元男' → Day Master, '偏官' → Seven Killings)
|
|
242
|
+
* 4. Na Yin by GanZhi (e.g. '甲子' → Sea Gold)
|
|
243
|
+
* 5. interaction by verb (e.g. '午子相冲' → Clash)
|
|
244
|
+
* Falls back to the original input when nothing matches.
|
|
245
|
+
*
|
|
246
|
+
* @example translate('元男') // 'Day Master'
|
|
247
|
+
* @example translate('午子相冲') // 'Clash'
|
|
248
|
+
* @example translate('甲子', 'zh') // '海中金'
|
|
249
|
+
*/
|
|
250
|
+
declare function translate(input: string, lang?: Lang): string;
|
|
251
|
+
|
|
252
|
+
export { ALL_TERMS, BRANCHES, BRANCH_BY_CHAR, BRANCH_BY_KEY, type BranchKey, type BranchTerm, ELEMENTS, ELEMENT_BY_CHAR, ELEMENT_BY_KEY, ELEMENT_CYCLES, type ElementKey, type ElementTerm, GENERAL_BY_KEY, GENERAL_BY_ZH, GENERAL_TERMS, GROWTH_STAGES, GROWTH_STAGE_BY_KEY, GROWTH_STAGE_BY_ZH, type GrowthStageKey, type GrowthStageTerm, INTERACTION_BY_ENUM, INTERACTION_BY_KEY, INTERACTION_TYPES, type InteractionTerm, type InteractionTypeKey, LIU_CHONG, LIU_HE, type Lang, NA_YIN, NA_YIN_BY_GAN_ZHI, NA_YIN_BY_ZH, type NaYinTerm, type Polarity, SAN_HE, SAN_HUI, SHEN_SHA, SHEN_SHA_BY_KEY, SHEN_SHA_BY_ZH, STEMS, STEM_BY_CHAR, STEM_BY_KEY, STEM_COMBINATIONS, type StemKey, type StemTerm, TEN_GODS, TEN_GOD_BY_KEY, TERM_BY_KEY, TERM_BY_ZH, type TenGodKey, type TenGodTerm, type Term, XIANG_HAI, XIANG_PO, XIANG_XING, branchByChar, elementOf, generalBy, generalByZh, growthStageByZh, interactionFromEnum, interactionFromZh, naYinOf, shenShaByZh, stemByChar, t, tenGodByZh, translate };
|