@nhatnguyet/cli 0.0.0-stage → 0.3.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 ADDED
@@ -0,0 +1,21 @@
1
+ MIT License
2
+
3
+ Copyright (c) 2026 Nhat Nguyet (nhatnguyet.org)
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in all
13
+ copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21
+ SOFTWARE.
package/README.md CHANGED
@@ -1,3 +1,95 @@
1
- # Temporary Holding Version
1
+ # @nhatnguyet/cli
2
2
 
3
- This version is a temporary placeholder for this package. An operational version to replace this has been submitted for review and is awaiting a staged release.
3
+ **Zi Wei Dou Shu, BaZi, numerology and the Vietnamese, Chinese, Korean and
4
+ Japanese lunar calendars in your terminal.** Charts print as grids, or as JSON
5
+ and SVG. English by default, Vietnamese and Chinese with `--lang`. Runs
6
+ locally with the [Nhat Nguyet](https://nhatnguyet.org/en/ma-nguon-mo)
7
+ libraries, checked against 17,291 core test vectors (18,819 including school options and
8
+ auspicious hours) and NASA, IMCCE data.
9
+
10
+ ```bash
11
+ npx @nhatnguyet/cli lunar 1985-01-21 --country CN
12
+ ```
13
+
14
+ ```text
15
+ ┌────────────┬──────────────┐
16
+ │ Gregorian │ 1985-01-21 │
17
+ │ Lunar │ 1984-12-01 │
18
+ │ Year │ Jia Zi · Rat │
19
+ │ Month │ Ding Chou │
20
+ │ Day │ Geng Shen │
21
+ │ Solar term │ Major Cold │
22
+ │ Calendar │ CN (UTC+8) │
23
+ └────────────┴──────────────┘
24
+ ```
25
+
26
+ Without `--country CN` the same day is Tết, `1985-01-01`, on the Vietnamese
27
+ calendar (UTC+7). Stems and branches print in pinyin; `--terms han` prints
28
+ 甲子, `--terms vi` the Sino-Vietnamese Giáp Tý.
29
+
30
+ ## Install
31
+
32
+ ```bash
33
+ npm i -g @nhatnguyet/cli # then: nhatnguyet ...
34
+ ```
35
+
36
+ Node.js 18 or newer. The Python package prints the same text:
37
+ `pip install nhatnguyet`, then `nhatnguyet ...` or `python -m nhatnguyet ...`.
38
+
39
+ ## Commands
40
+
41
+ ```text
42
+ nhatnguyet ziwei <YYYY-MM-DD> <HH:MM> <male|female> [--name "..."] [--year 2026] [school options]
43
+ nhatnguyet bazi <YYYY-MM-DD> [HH:MM] <male|female> [--zi-hour ...]
44
+ nhatnguyet lunar <YYYY-MM-DD> [--country VN|CN|KR|JP|...]
45
+ nhatnguyet solar <lunar YYYY-MM-DD> [--leap] [--country ...]
46
+ nhatnguyet terms <year> [--country ...]
47
+ nhatnguyet hours <YYYY-MM-DD> auspicious and inauspicious double hours of a day
48
+ nhatnguyet numerology "<full name>" <YYYY-MM-DD> [--today YYYY-MM-DD]
49
+ nhatnguyet festivals <year> [--ics]
50
+ ```
51
+
52
+ Each command also answers to the name of the matching MCP tool: `cast_ziwei`
53
+ (and the older `cast_zi_wei`, `zi_wei`), `cast_bazi`, `lunar_convert`,
54
+ `solar_terms`.
55
+
56
+ | Option | Meaning |
57
+ |---|---|
58
+ | `--lang en\|vi\|zh` | language of the result (default `en`) |
59
+ | `--terms pinyin\|han\|vi` | English only: stems, branches, the Four Transformations as pinyin (default, `Geng Wu`, `Hua Ji`), Chinese characters or Sino-Vietnamese |
60
+ | `--json` | print JSON instead of text |
61
+ | `--svg <file>` | also write the chart as SVG (`ziwei`, `bazi`, `numerology`) |
62
+ | `--ics` | `festivals`: print an iCalendar (`.ics`) file instead |
63
+ | `--theme dark` | dark SVG |
64
+ | `--no-color` | no ANSI colors (also when `NO_COLOR` is set or output is not a terminal) |
65
+
66
+ School options (`--fire-bell`, `--leap-month`, `--transformations`,
67
+ `--heavenly-kitchen`, `--injury-messenger`, `--zi-hour`) switch to the rule of
68
+ another named book where the books disagree; `nhatnguyet --help` lists their
69
+ values and
70
+ [docs/schools.md](https://github.com/Nhat-Nguyet/nhatnguyet-lunar-ziwei-bazi-numerology/blob/main/docs/schools.md)
71
+ names the sources.
72
+
73
+ Times are clock times; the Zi (Rat) double hour runs 23:00 to 00:59. Dates and times
74
+ are read as Vietnam time (UTC+7) unless `--country` says otherwise.
75
+
76
+ ```bash
77
+ nhatnguyet ziwei 1990-09-19 20:00 male --year 2026 # 12-palace grid, ten-year periods, patterns
78
+ nhatnguyet bazi 1990-09-19 female # birth time unknown: three pillars
79
+ nhatnguyet solar 2023-02-01 --leap # table for 2023-03-22, like lunar
80
+ nhatnguyet numerology "Nguyen Van An" 1990-09-19 --today 2026-11-19
81
+ nhatnguyet hours 2027-02-06 # the twelve double hours of Tết 2027
82
+ nhatnguyet festivals 2027 --ics > festivals-2027.ics # the year's festivals for a calendar app
83
+ nhatnguyet ziwei 1990-09-19 20:00 male --svg chart.svg --theme dark
84
+ ```
85
+
86
+ A full `ziwei` output is in the
87
+ [repository README](https://github.com/Nhat-Nguyet/nhatnguyet-lunar-ziwei-bazi-numerology#quick-start).
88
+ For AI assistants, the same calculations are available as an MCP server:
89
+ [`@nhatnguyet/mcp`](https://www.npmjs.com/package/@nhatnguyet/mcp).
90
+
91
+ ## License
92
+
93
+ MIT. Please credit `Data: Nhat Nguyet (nhatnguyet.org)` when you show results
94
+ to users. Zi Wei Dou Shu, BaZi and numerology are traditional systems, not
95
+ validated science.
package/dist/cli.d.ts ADDED
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env node
2
+ /** Version printed by --version. */
3
+ export declare const VERSION = "0.3.0";
4
+ export declare const HELP = "nhatnguyet: Zi Wei Dou Shu, BaZi, lunar calendar, numerology, Vietnamese festivals\n\nUsage:\n nhatnguyet ziwei <YYYY-MM-DD> <HH:MM> <male|female> [--name \"...\"] [--year 2026] [school options]\n nhatnguyet bazi <YYYY-MM-DD> [HH:MM] <male|female> [--zi-hour ...]\n nhatnguyet lunar <YYYY-MM-DD> [--country VN|CN|KR|JP|...]\n nhatnguyet solar <lunar YYYY-MM-DD> [--leap] [--country ...]\n nhatnguyet terms <year> [--country ...]\n nhatnguyet hours <YYYY-MM-DD> auspicious and inauspicious double hours of a day\n nhatnguyet numerology \"<full name>\" <YYYY-MM-DD> [--today YYYY-MM-DD]\n nhatnguyet festivals <year> [--ics]\n\nOptions:\n --lang en|vi|zh language of the result (default en)\n --terms pinyin|han|vi English only: stems, branches and transformations as\n pinyin (default, \"Geng Wu\"), Chinese characters or Sino-Vietnamese\n --json print JSON instead of text\n --svg <file> also write the chart as SVG (ziwei, bazi, numerology)\n --ics festivals: print an iCalendar (.ics) file instead\n --theme dark dark SVG\n --no-color no ANSI colours (also when NO_COLOR is set or output is not a terminal)\n\nSchool options (where the books disagree; default first, sources in docs/schools.md):\n --fire-bell vietnamese|quanshu|swap-for-female|swap-for-yin-male-yang-female\n --leap-month whole|split-at-15|next-month\n --transformations vietnamese|quanshu|zhongzhou (Geng year row)\n --heavenly-kitchen vietnamese|chinese (Gui year)\n --injury-messenger standard|zhongzhou\n --zi-hour next-day-from-23|split-at-midnight (bazi: day pillar from 23:00 to 24:00)\n\n -h, --help this help\n -v, --version version\n\nTimes are clock times; the Zi (Rat) double hour runs 23:00 to 00:59. Dates and times\nare read as Vietnam time (UTC+7) unless --country says otherwise (lunar, solar,\nterms, ziwei). Docs: https://nhatnguyet.org/en/ma-nguon-mo";
5
+ /** Parsed command line. */
6
+ export interface Args {
7
+ command: string;
8
+ positional: string[];
9
+ flags: Record<string, string | boolean>;
10
+ }
11
+ /** Split argv (without node and script) into command, positional arguments and flags. */
12
+ export declare function parseArgs(argv: string[]): Args;
13
+ /** Where `run` writes files (the SVG of --svg); tests pass their own. */
14
+ export interface RunEnv {
15
+ color: boolean;
16
+ width: number;
17
+ writeFile?: (path: string, data: string) => void;
18
+ }
19
+ /** Run one command; returns the text to print (no trailing newline). */
20
+ export declare function run(argv: string[], env: RunEnv): string;
package/dist/cli.js ADDED
@@ -0,0 +1,222 @@
1
+ #!/usr/bin/env node
2
+ // Lệnh dòng lệnh `nhatnguyet`: gọi lớp API tiếng Anh của các gói @nhatnguyet
3
+ // rồi in ra terminal (render.ts) hoặc JSON (--json).
4
+ //
5
+ // Command line for the Nhat Nguyet libraries.
6
+ import { auspiciousHours, checkTerms, solarTerms, toLunar, toSolar } from "@nhatnguyet/am-lich";
7
+ import { castZiWei, decadeLuck, findPatterns, yearlyLuck, ziWeiSvg } from "@nhatnguyet/tu-vi";
8
+ import { baZiSvg, castBaZi } from "@nhatnguyet/bat-tu";
9
+ import { numerology, numerologySvg } from "@nhatnguyet/than-so-hoc";
10
+ import { writeFileSync } from "node:fs";
11
+ import { festivals, festivalsIcs } from "@nhatnguyet/le-hoi";
12
+ import { renderBaZi, renderFestivals, renderHours, renderLunar, renderNumerology, renderSolarTerms, renderZiWei } from "./render.js";
13
+ /** Version printed by --version. */
14
+ export const VERSION = "0.3.0";
15
+ export const HELP = `nhatnguyet: Zi Wei Dou Shu, BaZi, lunar calendar, numerology, Vietnamese festivals
16
+
17
+ Usage:
18
+ nhatnguyet ziwei <YYYY-MM-DD> <HH:MM> <male|female> [--name "..."] [--year 2026] [school options]
19
+ nhatnguyet bazi <YYYY-MM-DD> [HH:MM] <male|female> [--zi-hour ...]
20
+ nhatnguyet lunar <YYYY-MM-DD> [--country VN|CN|KR|JP|...]
21
+ nhatnguyet solar <lunar YYYY-MM-DD> [--leap] [--country ...]
22
+ nhatnguyet terms <year> [--country ...]
23
+ nhatnguyet hours <YYYY-MM-DD> auspicious and inauspicious double hours of a day
24
+ nhatnguyet numerology "<full name>" <YYYY-MM-DD> [--today YYYY-MM-DD]
25
+ nhatnguyet festivals <year> [--ics]
26
+
27
+ Options:
28
+ --lang en|vi|zh language of the result (default en)
29
+ --terms pinyin|han|vi English only: stems, branches and transformations as
30
+ pinyin (default, "Geng Wu"), Chinese characters or Sino-Vietnamese
31
+ --json print JSON instead of text
32
+ --svg <file> also write the chart as SVG (ziwei, bazi, numerology)
33
+ --ics festivals: print an iCalendar (.ics) file instead
34
+ --theme dark dark SVG
35
+ --no-color no ANSI colours (also when NO_COLOR is set or output is not a terminal)
36
+
37
+ School options (where the books disagree; default first, sources in docs/schools.md):
38
+ --fire-bell vietnamese|quanshu|swap-for-female|swap-for-yin-male-yang-female
39
+ --leap-month whole|split-at-15|next-month
40
+ --transformations vietnamese|quanshu|zhongzhou (Geng year row)
41
+ --heavenly-kitchen vietnamese|chinese (Gui year)
42
+ --injury-messenger standard|zhongzhou
43
+ --zi-hour next-day-from-23|split-at-midnight (bazi: day pillar from 23:00 to 24:00)
44
+
45
+ -h, --help this help
46
+ -v, --version version
47
+
48
+ Times are clock times; the Zi (Rat) double hour runs 23:00 to 00:59. Dates and times
49
+ are read as Vietnam time (UTC+7) unless --country says otherwise (lunar, solar,
50
+ terms, ziwei). Docs: https://nhatnguyet.org/en/ma-nguon-mo`;
51
+ // Mọi tên công cụ MCP cũng là bí danh của lệnh tương ứng (cast_ziwei, solar_terms...).
52
+ const ALIAS = {
53
+ ziwei: "ziwei", "zi-wei": "ziwei", zi_wei: "ziwei", cast_ziwei: "ziwei", cast_zi_wei: "ziwei", tuvi: "ziwei", "tu-vi": "ziwei",
54
+ bazi: "bazi", "ba-zi": "bazi", cast_bazi: "bazi", battu: "bazi", "bat-tu": "bazi",
55
+ lunar: "lunar", lunar_convert: "lunar", amlich: "lunar", "am-lich": "lunar",
56
+ solar: "solar", duong: "solar",
57
+ terms: "terms", "solar-terms": "terms", solar_terms: "terms", tietkhi: "terms",
58
+ hours: "hours", auspicious_hours: "hours", "auspicious-hours": "hours", "gio-hoang-dao": "hours",
59
+ numerology: "numerology", "than-so-hoc": "numerology",
60
+ festivals: "festivals", "le-hoi": "festivals", lehoi: "festivals",
61
+ };
62
+ // Cờ lựa chọn phái: tên cờ (kebab-case) và khoá của `schools`.
63
+ const SCHOOL_FLAGS = ["fire-bell", "leap-month", "transformations", "heavenly-kitchen", "injury-messenger", "zi-hour"];
64
+ /** Lựa chọn phái từ các cờ (chỉ những cờ có mặt); undefined khi không có cờ nào. */
65
+ function schoolsFrom(flags, keys) {
66
+ const r = {};
67
+ for (const f of keys) {
68
+ const v = flags[f];
69
+ if (v === undefined)
70
+ continue;
71
+ if (typeof v !== "string")
72
+ throw new TypeError(`--${f} needs a value`);
73
+ r[f.replace(/-(\w)/g, (_, c) => c.toUpperCase())] = v;
74
+ }
75
+ return Object.keys(r).length ? r : undefined;
76
+ }
77
+ /** Split argv (without node and script) into command, positional arguments and flags. */
78
+ export function parseArgs(argv) {
79
+ const positional = [];
80
+ const flags = {};
81
+ const coGiaTri = new Set(["lang", "country", "name", "year", "today", "tz", "svg", "theme", "terms", ...SCHOOL_FLAGS]);
82
+ for (let i = 0; i < argv.length; i++) {
83
+ const a = argv[i];
84
+ if (a === "-h")
85
+ flags.help = true;
86
+ else if (a === "-v")
87
+ flags.version = true;
88
+ else if (a.startsWith("--")) {
89
+ const eq = a.indexOf("=");
90
+ const k = eq > 0 ? a.slice(2, eq) : a.slice(2);
91
+ if (eq > 0)
92
+ flags[k] = a.slice(eq + 1);
93
+ else if (coGiaTri.has(k)) {
94
+ if (i + 1 >= argv.length)
95
+ throw new Error(`--${k} needs a value`);
96
+ flags[k] = argv[++i];
97
+ }
98
+ else
99
+ flags[k] = true;
100
+ }
101
+ else
102
+ positional.push(a);
103
+ }
104
+ const lenh = positional.shift() ?? "";
105
+ return { command: ALIAS[lenh.toLowerCase()] ?? lenh, positional, flags };
106
+ }
107
+ const GIOI = /^(male|female|m|f|nam|nữ|nu)$/i;
108
+ /** Run one command; returns the text to print (no trailing newline). */
109
+ export function run(argv, env) {
110
+ const { command, positional: p, flags } = parseArgs(argv);
111
+ if (flags.version)
112
+ return VERSION;
113
+ if (flags.help || command === "" || command === "help")
114
+ return HELP;
115
+ const lang = (typeof flags.lang === "string" ? flags.lang : "en");
116
+ const terms = checkTerms(typeof flags.terms === "string" ? flags.terms : undefined, lang === "vi" || lang === "zh" ? lang : "en");
117
+ const json = flags.json === true;
118
+ const opts = { color: env.color && flags.color !== false && flags["no-color"] !== true, width: env.width };
119
+ const country = typeof flags.country === "string" ? flags.country : undefined;
120
+ const can = (n, mau) => {
121
+ if (p.length < n)
122
+ throw new Error(`usage: nhatnguyet ${mau}`);
123
+ };
124
+ const dumpJson = (x) => JSON.stringify(x, (k, v) => (k === "raw" ? undefined : v), 2);
125
+ const theme = flags.theme === "dark" ? "dark" : "light";
126
+ const ghiSvg = (ve) => {
127
+ if (typeof flags.svg !== "string")
128
+ return;
129
+ (env.writeFile ?? writeFileSync)(flags.svg, ve() + "\n");
130
+ };
131
+ switch (command) {
132
+ case "ziwei": {
133
+ can(3, "ziwei <YYYY-MM-DD> <HH:MM> <male|female>");
134
+ const year = typeof flags.year === "string" ? Number(flags.year) : undefined;
135
+ const schools = schoolsFrom(flags, SCHOOL_FLAGS.slice(0, 5));
136
+ const chart = castZiWei({ date: p[0], time: p[1], gender: p[2], name: typeof flags.name === "string" ? flags.name : undefined, lang, terms, viewYear: year, schools, country });
137
+ const extra = { decades: decadeLuck(chart), year: yearlyLuck(chart), patterns: findPatterns(chart) };
138
+ ghiSvg(() => ziWeiSvg(chart, { theme }));
139
+ if (json)
140
+ return dumpJson({ chart, ...extra });
141
+ return renderZiWei(chart, extra, opts);
142
+ }
143
+ case "bazi": {
144
+ can(2, "bazi <YYYY-MM-DD> [HH:MM] <male|female>");
145
+ const coGio = p.length >= 3 || !GIOI.test(p[1]);
146
+ if (coGio)
147
+ can(3, "bazi <YYYY-MM-DD> [HH:MM] <male|female>");
148
+ const chart = castBaZi({ date: p[0], time: coGio ? p[1] : null, gender: coGio ? p[2] : p[1], lang, terms, schools: schoolsFrom(flags, ["zi-hour"]) });
149
+ ghiSvg(() => baZiSvg(chart, { theme, name: typeof flags.name === "string" ? flags.name : "" }));
150
+ return json ? dumpJson(chart) : renderBaZi(chart, opts);
151
+ }
152
+ case "lunar": {
153
+ can(1, "lunar <YYYY-MM-DD> [--country CN]");
154
+ const r = toLunar(p[0], { country, lang, terms });
155
+ return json ? dumpJson(r) : renderLunar(r, opts);
156
+ }
157
+ case "solar": {
158
+ can(1, "solar <lunar YYYY-MM-DD> [--leap]");
159
+ const k = /^(-?\d+)-(\d+)-(\d+)$/.exec(p[0]);
160
+ if (!k)
161
+ throw new Error("lunar date must look like YYYY-MM-DD");
162
+ const r = toSolar({ year: Number(k[1]), month: Number(k[2]), day: Number(k[3]), leap: flags.leap === true }, { country });
163
+ // Bảng như lệnh lunar, dựng từ ngày dương vừa đổi được.
164
+ return json ? dumpJson(r) : renderLunar(toLunar(r.date, { country, lang, terms }), opts);
165
+ }
166
+ case "terms": {
167
+ can(1, "terms <year>");
168
+ const y = Number(p[0]);
169
+ const t = solarTerms(y, { country, lang });
170
+ return json ? dumpJson(t) : renderSolarTerms(y, t, lang, opts, terms);
171
+ }
172
+ case "hours": {
173
+ can(1, "hours <YYYY-MM-DD>");
174
+ const r = auspiciousHours(p[0], { lang, terms });
175
+ return json ? dumpJson(r) : renderHours(r, opts);
176
+ }
177
+ case "numerology": {
178
+ can(2, 'numerology "<full name>" <YYYY-MM-DD>');
179
+ const r = numerology({ name: p[0], birthDate: p[1], today: typeof flags.today === "string" ? flags.today : undefined, lang });
180
+ ghiSvg(() => numerologySvg(r, { theme }));
181
+ return json ? dumpJson(r) : renderNumerology(r, opts);
182
+ }
183
+ case "festivals": {
184
+ can(1, "festivals <year>");
185
+ const y = Number(p[0]);
186
+ // --ics: tệp kết thúc bằng CRLF; main() thêm "\n" nên bỏ "\n" cuối ở đây.
187
+ if (flags.ics === true)
188
+ return festivalsIcs(y, { lang }).slice(0, -1);
189
+ const list = festivals(y, { lang });
190
+ return json ? dumpJson(list) : renderFestivals(y, list, lang, opts);
191
+ }
192
+ }
193
+ throw new Error(`unknown command "${command}". Try: nhatnguyet --help`);
194
+ }
195
+ function main() {
196
+ const out = process.stdout;
197
+ const env = process.env;
198
+ const ep = env.FORCE_COLOR !== undefined && env.FORCE_COLOR !== "0";
199
+ const color = env.NO_COLOR === undefined && (ep || (!!out.isTTY && env.TERM !== "dumb"));
200
+ const width = out.isTTY && out.columns ? Math.min(out.columns, 140) : 88;
201
+ // Người đọc đóng ống sớm (`nhatnguyet festivals 2027 --ics | head`): thoát
202
+ // êm với mã 0 như lệnh Unix thường, không in lỗi EPIPE.
203
+ out.on("error", (e) => {
204
+ if (e.code === "EPIPE")
205
+ process.exit(0);
206
+ throw e;
207
+ });
208
+ try {
209
+ out.write(run(process.argv.slice(2), { color, width }) + "\n");
210
+ }
211
+ catch (e) {
212
+ process.stderr.write("nhatnguyet: " + (e instanceof Error ? e.message : String(e)) + "\n");
213
+ process.exitCode = 1;
214
+ }
215
+ }
216
+ // Chạy khi được gọi như chương trình (không chạy khi test nhập mô-đun).
217
+ const laChuongTrinh = (() => {
218
+ const a = process.argv[1] ?? "";
219
+ return /(?:^|[\\/])(?:cli\.(?:ts|js)|nhatnguyet)$/.test(a) || a.includes("/.bin/") || a.includes("@nhatnguyet/cli");
220
+ })();
221
+ if (laChuongTrinh)
222
+ main();
@@ -0,0 +1,52 @@
1
+ import type { AuspiciousHoursResult, LunarResult, SolarTerm, Terms } from "@nhatnguyet/am-lich";
2
+ import type { ZiWeiChart, DecadeLuck, YearlyLuck, ZiWeiPattern } from "@nhatnguyet/tu-vi";
3
+ import type { BaZiChart } from "@nhatnguyet/bat-tu";
4
+ import type { NumerologyResult } from "@nhatnguyet/than-so-hoc";
5
+ import type { Festival } from "@nhatnguyet/le-hoi";
6
+ type Lang = "vi" | "en" | "zh";
7
+ /** Rendering options. */
8
+ export interface RenderOptions {
9
+ /** Use ANSI colours. Default false. */
10
+ color?: boolean;
11
+ /** Total width available, in terminal columns. Default 88. */
12
+ width?: number;
13
+ }
14
+ /** Terminal columns taken by one code point: 2 for CJK and fullwidth, 0 for combining marks. */
15
+ export declare function charWidth(cp: number): number;
16
+ /** Display width of a string (no ANSI codes inside). */
17
+ export declare function displayWidth(s: string): number;
18
+ /** Cut a string to at most `width` columns, ending with "…" when cut. */
19
+ export declare function truncate(s: string, width: number): string;
20
+ /** Wrap words into lines of at most `width` columns (CJK text breaks anywhere). */
21
+ export declare function wrap(s: string, width: number): string[];
22
+ /** Pack items into lines of at most `width` columns, never splitting an item (long items are cut). */
23
+ export declare function wrapItems(items: string[], sep: string, width: number): string[];
24
+ /**
25
+ * The Zi Wei chart as a 4x4 grid: the twelve palaces around the edge (Tỵ at
26
+ * the top left, as in printed charts), birth data in the middle.
27
+ */
28
+ export declare function renderZiWeiGrid(chart: ZiWeiChart, opts?: RenderOptions): string;
29
+ /** Grid plus the viewing year, ten-year periods, patterns and notes. */
30
+ export declare function renderZiWei(chart: ZiWeiChart, extra: {
31
+ decades?: DecadeLuck[];
32
+ year?: YearlyLuck;
33
+ patterns?: ZiWeiPattern[];
34
+ }, opts?: RenderOptions): string;
35
+ /** The four pillars as a table, then the luck pillars. */
36
+ export declare function renderBaZi(chart: BaZiChart, opts?: RenderOptions): string;
37
+ /** A lunar date as a small key-value box. */
38
+ export declare function renderLunar(r: LunarResult, opts?: RenderOptions): string;
39
+ /**
40
+ * The 24 solar terms of a year as a table. The name is in `lang` only; in
41
+ * English, `nameTerms` "han" or "vi" adds the Chinese or Vietnamese name in
42
+ * brackets ("Minor Cold (小寒)", "Minor Cold (Tiểu Hàn)"), "pinyin" (default)
43
+ * adds nothing.
44
+ */
45
+ export declare function renderSolarTerms(year: number, terms: SolarTerm[], lang: Lang, opts?: RenderOptions, nameTerms?: Terms): string;
46
+ /** The twelve double hours of a day: branch, clock range, auspicious or not, spirit. */
47
+ export declare function renderHours(r: AuspiciousHoursResult, opts?: RenderOptions): string;
48
+ /** Numerology numbers, the 3x3 birth-date grid, pinnacles and challenges. */
49
+ export declare function renderNumerology(r: NumerologyResult, opts?: RenderOptions): string;
50
+ /** Festivals of a year as a table: date, fixed date, name. */
51
+ export declare function renderFestivals(year: number, list: Festival[], lang: Lang, opts?: RenderOptions): string;
52
+ export {};