vietnamese-lunar 1.0.0 → 2.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.
Files changed (70) hide show
  1. package/CHANGELOG.md +66 -0
  2. package/lib/cjs/auspiciousHours.d.ts +7 -0
  3. package/lib/cjs/auspiciousHours.js +57 -0
  4. package/lib/cjs/compat.d.ts +8 -0
  5. package/lib/cjs/compat.js +24 -0
  6. package/lib/{constants.d.ts → cjs/constants.d.ts} +3 -5
  7. package/lib/{constants.js → cjs/constants.js} +8 -25
  8. package/lib/cjs/dayStar.d.ts +14 -0
  9. package/lib/cjs/dayStar.js +64 -0
  10. package/lib/cjs/heavenly_earthly.d.ts +8 -0
  11. package/lib/cjs/heavenly_earthly.js +57 -0
  12. package/lib/cjs/holidays.d.ts +10 -0
  13. package/lib/cjs/holidays.js +126 -0
  14. package/lib/cjs/index.d.ts +9 -0
  15. package/lib/cjs/index.js +33 -0
  16. package/lib/cjs/input.d.ts +5 -0
  17. package/lib/cjs/input.js +39 -0
  18. package/lib/cjs/lunar.d.ts +9 -0
  19. package/lib/cjs/lunar.js +115 -0
  20. package/lib/cjs/lunarConverter.d.ts +7 -0
  21. package/lib/cjs/lunarConverter.js +102 -0
  22. package/lib/cjs/package.json +1 -0
  23. package/lib/cjs/solarTerms.d.ts +5 -0
  24. package/lib/cjs/solarTerms.js +82 -0
  25. package/lib/cjs/type.d.ts +135 -0
  26. package/lib/{utils.d.ts → cjs/utils.d.ts} +7 -0
  27. package/lib/{utils.js → cjs/utils.js} +26 -6
  28. package/lib/esm/auspiciousHours.d.ts +7 -0
  29. package/lib/esm/auspiciousHours.js +50 -0
  30. package/lib/esm/compat.d.ts +8 -0
  31. package/lib/esm/compat.js +19 -0
  32. package/lib/esm/constants.d.ts +14 -0
  33. package/lib/esm/constants.js +117 -0
  34. package/lib/esm/dayStar.d.ts +14 -0
  35. package/lib/esm/dayStar.js +58 -0
  36. package/lib/esm/heavenly_earthly.d.ts +8 -0
  37. package/lib/esm/heavenly_earthly.js +48 -0
  38. package/lib/esm/holidays.d.ts +10 -0
  39. package/lib/esm/holidays.js +120 -0
  40. package/lib/esm/index.d.ts +9 -0
  41. package/lib/esm/index.js +8 -0
  42. package/lib/esm/input.d.ts +5 -0
  43. package/lib/esm/input.js +35 -0
  44. package/lib/esm/lunar.d.ts +9 -0
  45. package/lib/esm/lunar.js +107 -0
  46. package/lib/esm/lunarConverter.d.ts +7 -0
  47. package/lib/esm/lunarConverter.js +95 -0
  48. package/lib/esm/package.json +1 -0
  49. package/lib/esm/solarTerms.d.ts +5 -0
  50. package/lib/esm/solarTerms.js +77 -0
  51. package/lib/esm/type.d.ts +135 -0
  52. package/lib/esm/type.js +1 -0
  53. package/lib/esm/utils.d.ts +10 -0
  54. package/lib/esm/utils.js +51 -0
  55. package/package.json +60 -21
  56. package/readme.md +232 -8
  57. package/lib/auspiciousHours.d.ts +0 -4
  58. package/lib/auspiciousHours.js +0 -38
  59. package/lib/heavenly_earthly.d.ts +0 -3
  60. package/lib/heavenly_earthly.js +0 -30
  61. package/lib/holidays.d.ts +0 -1
  62. package/lib/holidays.js +0 -25
  63. package/lib/index.d.ts +0 -1
  64. package/lib/index.js +0 -6
  65. package/lib/lunar.d.ts +0 -3
  66. package/lib/lunar.js +0 -111
  67. package/lib/lunarConverter.d.ts +0 -2
  68. package/lib/lunarConverter.js +0 -63
  69. package/lib/type.d.ts +0 -13
  70. /package/lib/{type.js → cjs/type.js} +0 -0
package/CHANGELOG.md ADDED
@@ -0,0 +1,66 @@
1
+ # Changelog
2
+
3
+ All notable changes to this package are documented here. Versions follow [Semantic Versioning](https://semver.org/): a **major** bump (1.x → 2.x) means you may need to change your code.
4
+
5
+ ## 2.1.0 — 2026-11-01
6
+
7
+ Backward compatible with 2.0.x: no existing field changed name or type; everything below is additive.
8
+
9
+ ### Added
10
+
11
+ - **Input types**: `dayInfo`, `lunarDay`, `getHourInfo` accept `'d/m/yyyy'`, a `Date` (local time) or `{day, month, year}`.
12
+ - **Hoàng Đạo / Hắc Đạo**: `dayStar` gains `index` (1..12), `category` (`'hoang-dao' | 'hac-dao' | null`), `system`, `aliases`. `dayInfo(date, {starSystem: 'hiep-ky' | 'ngoc-hap'})`, default `'hiep-ky'`. `isAuspicious` is kept, but `false` no longer implies hắc đạo — use `category`.
13
+ - `getSolarDate(day, month, lunarYear, isLeap?)` (lunar → solar, `null` when it does not exist), `getLeapMonth(lunarYear)`, `getLunarMonthDays(month, lunarYear, isLeap?)`, and `monthDays` on `getLunarDate()` / `dayInfo().lunarDate`.
14
+ - `dayInfo().hours` (12 structured hours with Can Chi, range, star, category) and `getHourInfo(date, hour)`.
15
+ - `dayInfo().solarTerm` (`current` / `next` with exact start time and `daysUntil`) and `getSolarTerms(year)`.
16
+ - `getHolidays(year)`, `nextHolidays(from, count)`; holidays gain `type` and `isDayOff`.
17
+ - `dayInfo().clash` / `compatible` (tuổi xung, tam hợp, lục hợp).
18
+ - `dayInfo().napAm` and `element`. `dayMaster` is **deprecated** (it always returned Nạp âm); it keeps its value.
19
+ - `dayInfo().canChi` (numeric Can/Chi indexes of day, month, year, first hour) and `getCanChi(lunar)`.
20
+ - `monthInfo(year, month)` — all days of a solar month in one call. Internal caching of decoded lunar years and solar-term times.
21
+ - Dual package: ESM (`lib/esm`) + CJS (`lib/cjs`) with `exports` map and full `.d.ts`.
22
+
23
+ ### Changed
24
+
25
+ - `moment` is no longer a dependency (date parsing is built in; same accepted formats).
26
+ - Build output moved from `lib/*.js` to `lib/cjs` and `lib/esm`. `require('vietnamese-lunar')` / `import` keep working; deep imports of `vietnamese-lunar/lib/...` do not.
27
+
28
+ ### Not included (item 10 of the request)
29
+
30
+ 12 Trực, 28 Sao, ngày kỵ and a composite `rating` are not implemented: they need a chosen authoritative source and weights; see README.
31
+
32
+ ## 2.0.0 — 2026-10-26
33
+
34
+ ### ⚠️ Breaking changes
35
+
36
+ - `dayInfo().holiday` (string) is replaced by `dayInfo().holidays` (array). A day can now have several holidays (e.g. 2/9/2020 is both Ngày Quốc khánh and Lễ Vu Lan).
37
+
38
+ ```javascript
39
+ // v1
40
+ if (info.holiday) show(info.holiday);
41
+ // v2
42
+ info.holidays.forEach(h => show(h.name)); // h: { name, calendar: "solar" | "lunar", isPublicHoliday }
43
+ ```
44
+
45
+ - `auspiciousHours` / `inAuspiciousHours`: the Heavenly Stem (Can) of each hour was wrong in v1 and is now fixed (Ngũ Thử Độn rule). Hour branches and time ranges are unchanged, only the stem text differs — e.g. 7/1/2025: `Giáp Tý (23-1)` → `Mậu Tý (23-1)`.
46
+
47
+ ### Added
48
+
49
+ - `dayStar`: Hoàng Đạo / Hắc Đạo day (12-star system, Nguyệt Kiến by solar terms).
50
+ - Solar holidays (Tết Dương lịch, 30/4, 1/5, 2/9, 24/11 from 2026, …), Giao thừa, and `isPublicHoliday` per Labor Code Art. 112.
51
+ - New exports: `getLunarDate`, `getJulianDayNumber`, `getSolarTermIndex`, `getHeavenlyEarthly`, `getDayStemIndex`, `getDayBranchIndex`, `getMonthBranchIndex`, `getDayStarInfo`, `HEAVENLY_STEMS`, `EARTHLY_BRANCHES`, `SOLAR_TERMS`.
52
+ - TypeScript types: `DayInfo`, `LunarDayInfo`, `LunarDate`, `DayStarInfo`, `Holiday`, `dateFormat`.
53
+
54
+ ### Fixed
55
+
56
+ - Year 1800 was rejected as invalid input.
57
+ - Lunar holidays were repeated in leap months (e.g. Lễ Vu Lan twice in 2006).
58
+ - Importing internal modules in some orders crashed with `ReferenceError` (circular import).
59
+
60
+ ### Unchanged
61
+
62
+ - Solar → lunar conversion (`lunarDay()`, `lunarDate`, `lunarDateText`), `firstHour`, `solarTerms`, `dayMaster` — identical output to v1 for 1801–2199.
63
+
64
+ ## 1.0.0 — 2025-11-22
65
+
66
+ - Initial release: `dayInfo()`, `lunarDay()`.
@@ -0,0 +1,7 @@
1
+ import { HourInfo, StarSystem } from "./type.js";
2
+ export declare const getAuspiciousHours: (julianDay: number) => string;
3
+ export declare const getInauspiciousHours: (julianDay: number) => string;
4
+ /** 12 giờ của ngày (Tý → Hợi) kèm thần trực giờ và phân loại theo `system`. */
5
+ export declare const getHours: (julianDay: number, system?: StarSystem) => HourInfo[];
6
+ /** Giờ dương lịch 0..23 → chỉ số giờ Chi (23 và 0 đều là giờ Tý). */
7
+ export declare const hourToBranchIndex: (hour: number) => number;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.hourToBranchIndex = exports.getHours = exports.getInauspiciousHours = exports.getAuspiciousHours = void 0;
4
+ const constants_js_1 = require("./constants.js");
5
+ const heavenly_earthly_js_1 = require("./heavenly_earthly.js");
6
+ const dayStar_js_1 = require("./dayStar.js");
7
+ const getHourStemIndex = (julianDay, hour) => {
8
+ const firstHourStemIndex = (julianDay - 1) * 2 % 10;
9
+ return (firstHourStemIndex + hour) % 10;
10
+ };
11
+ const hourText = (julianDay, hour) => {
12
+ const start = (hour * 2 + 23) % 24;
13
+ const end = (hour * 2 + 1) % 24;
14
+ return `${constants_js_1.HEAVENLY_STEMS[getHourStemIndex(julianDay, hour)]} ${constants_js_1.EARTHLY_BRANCHES[hour]} (${start}-${end})`;
15
+ };
16
+ const getAuspiciousHours = (julianDay) => {
17
+ const pattern = constants_js_1.AUSPICIOUS_HOURS[(0, heavenly_earthly_js_1.getDayBranchIndex)(julianDay) % 6];
18
+ const list = [];
19
+ for (let hour = 0; hour < 12; hour++) {
20
+ if (pattern.charAt(hour) === '1')
21
+ list.push(hourText(julianDay, hour));
22
+ }
23
+ return list.join(', ');
24
+ };
25
+ exports.getAuspiciousHours = getAuspiciousHours;
26
+ const getInauspiciousHours = (julianDay) => {
27
+ const pattern = constants_js_1.AUSPICIOUS_HOURS[(0, heavenly_earthly_js_1.getDayBranchIndex)(julianDay) % 6];
28
+ if (!pattern || pattern.length < 12)
29
+ return '';
30
+ const list = [];
31
+ for (let hour = 0; hour < 12; hour++) {
32
+ if (pattern.charAt(hour) !== '1')
33
+ list.push(hourText(julianDay, hour));
34
+ }
35
+ return list.join(', ');
36
+ };
37
+ exports.getInauspiciousHours = getInauspiciousHours;
38
+ /** 12 giờ của ngày (Tý → Hợi) kèm thần trực giờ và phân loại theo `system`. */
39
+ const getHours = (julianDay, system = 'hiep-ky') => {
40
+ const hours = [];
41
+ for (let hour = 0; hour < 12; hour++) {
42
+ const position = (0, dayStar_js_1.getHourStarPosition)(julianDay, hour);
43
+ hours.push({
44
+ chi: constants_js_1.EARTHLY_BRANCHES[hour],
45
+ canChi: `${constants_js_1.HEAVENLY_STEMS[getHourStemIndex(julianDay, hour)]} ${constants_js_1.EARTHLY_BRANCHES[hour]}`,
46
+ start: (hour * 2 + 23) % 24,
47
+ end: (hour * 2 + 1) % 24,
48
+ star: dayStar_js_1.STAR_DEFINITIONS[position].name,
49
+ category: (0, dayStar_js_1.getStarCategory)(position, system),
50
+ });
51
+ }
52
+ return hours;
53
+ };
54
+ exports.getHours = getHours;
55
+ /** Giờ dương lịch 0..23 → chỉ số giờ Chi (23 và 0 đều là giờ Tý). */
56
+ const hourToBranchIndex = (hour) => Math.floor(((hour + 1) % 24) / 2);
57
+ exports.hourToBranchIndex = hourToBranchIndex;
@@ -0,0 +1,8 @@
1
+ export declare const getClash: (dayCan: number, dayChi: number) => {
2
+ canChi: string[];
3
+ chi: string[];
4
+ };
5
+ export declare const getCompatible: (dayChi: number) => {
6
+ tamHop: string[];
7
+ lucHop: string;
8
+ };
@@ -0,0 +1,24 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCompatible = exports.getClash = void 0;
4
+ const constants_js_1 = require("./constants.js");
5
+ // Tam hợp: Thân-Tý-Thìn, Hợi-Mão-Mùi, Dần-Ngọ-Tuất, Tỵ-Dậu-Sửu (Chi cách nhau 4).
6
+ // Lục hợp: Tý-Sửu, Dần-Hợi, Mão-Tuất, Thìn-Dậu, Tỵ-Thân, Ngọ-Mùi (tổng chỉ số ≡ 1 mod 12).
7
+ // Lục xung: Chi đối nhau (cách 6).
8
+ // Thiên khắc địa xung: Chi đối nhau + Can tương xung (Giáp-Canh, Ất-Tân, Bính-Nhâm, Đinh-Quý).
9
+ // Mậu và Kỷ không có Can xung, nên với ngày Mậu/Kỷ `canChi` rỗng (vẫn có `chi`).
10
+ const getClashCan = (can) => (can <= 3 ? can + 6 : can >= 6 ? can - 6 : -1);
11
+ const getClash = (dayCan, dayChi) => {
12
+ const oppositeChi = (dayChi + 6) % 12;
13
+ const clashCan = getClashCan(dayCan);
14
+ return {
15
+ canChi: clashCan === -1 ? [] : [`${constants_js_1.HEAVENLY_STEMS[clashCan]} ${constants_js_1.EARTHLY_BRANCHES[oppositeChi]}`],
16
+ chi: [constants_js_1.EARTHLY_BRANCHES[oppositeChi]],
17
+ };
18
+ };
19
+ exports.getClash = getClash;
20
+ const getCompatible = (dayChi) => ({
21
+ tamHop: [constants_js_1.EARTHLY_BRANCHES[(dayChi + 4) % 12], constants_js_1.EARTHLY_BRANCHES[(dayChi + 8) % 12]],
22
+ lucHop: constants_js_1.EARTHLY_BRANCHES[(13 - dayChi) % 12],
23
+ });
24
+ exports.getCompatible = getCompatible;
@@ -4,13 +4,11 @@ declare const EARTHLY_BRANCHES: string[];
4
4
  declare const AUSPICIOUS_HOURS: string[];
5
5
  declare const SOLAR_TERMS: string[];
6
6
  declare const HEAVENLY_EARTHLY_ELEMENT_MAP: Record<string, string>;
7
- declare const AUSPICIOUS: string[];
8
- declare const INAUSPICIOUS: string[];
9
- declare const ZODIAC_SIGNS: Record<string, string[]>;
7
+ declare const DAY_STARS: string[];
8
+ declare const AUSPICIOUS_DAY_STARS: string[];
10
9
  declare const LEAP_TEXT = " (nhu\u1EADn)";
11
10
  declare const DAY_OF_WEEK: string[];
12
11
  declare const FIRST_DAY: number;
13
12
  declare const LAST_DAY: number;
14
- declare const DATE_FORMAT: string[];
15
13
  declare const PI: number;
16
- export { LIST_YEARS, FIRST_DAY, LAST_DAY, PI, HEAVENLY_STEMS, EARTHLY_BRANCHES, AUSPICIOUS_HOURS, SOLAR_TERMS, DAY_OF_WEEK, LEAP_TEXT, DATE_FORMAT, HEAVENLY_EARTHLY_ELEMENT_MAP, AUSPICIOUS, INAUSPICIOUS, ZODIAC_SIGNS };
14
+ export { LIST_YEARS, FIRST_DAY, LAST_DAY, PI, HEAVENLY_STEMS, EARTHLY_BRANCHES, AUSPICIOUS_HOURS, SOLAR_TERMS, DAY_OF_WEEK, LEAP_TEXT, HEAVENLY_EARTHLY_ELEMENT_MAP, DAY_STARS, AUSPICIOUS_DAY_STARS };
@@ -1,7 +1,7 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.ZODIAC_SIGNS = exports.INAUSPICIOUS = exports.AUSPICIOUS = exports.HEAVENLY_EARTHLY_ELEMENT_MAP = exports.DATE_FORMAT = exports.LEAP_TEXT = exports.DAY_OF_WEEK = exports.SOLAR_TERMS = exports.AUSPICIOUS_HOURS = exports.EARTHLY_BRANCHES = exports.HEAVENLY_STEMS = exports.PI = exports.LAST_DAY = exports.FIRST_DAY = exports.LIST_YEARS = void 0;
4
- const utils_1 = require("./utils");
3
+ exports.AUSPICIOUS_DAY_STARS = exports.DAY_STARS = exports.HEAVENLY_EARTHLY_ELEMENT_MAP = exports.LEAP_TEXT = exports.DAY_OF_WEEK = exports.SOLAR_TERMS = exports.AUSPICIOUS_HOURS = exports.EARTHLY_BRANCHES = exports.HEAVENLY_STEMS = exports.PI = exports.LAST_DAY = exports.FIRST_DAY = exports.LIST_YEARS = void 0;
4
+ const utils_js_1 = require("./utils.js");
5
5
  const LIST_YEARS = [
6
6
  0x30baa3, 0x56ab50, 0x422ba0, 0x2cab61, 0x52a370, 0x3c51e8, 0x60d160, 0x4ae4b0, 0x376926, 0x58daa0,
7
7
  0x445b50, 0x3116d2, 0x562ae0, 0x3ea2e0, 0x28e2d2, 0x4ec950, 0x38d556, 0x5cb520, 0x46b690, 0x325da4,
@@ -116,34 +116,17 @@ const HEAVENLY_EARTHLY_ELEMENT_MAP = {
116
116
  'Quý Hợi': 'Đại Hải Thủy'
117
117
  };
118
118
  exports.HEAVENLY_EARTHLY_ELEMENT_MAP = HEAVENLY_EARTHLY_ELEMENT_MAP;
119
- const AUSPICIOUS = ['Thanh Long', 'Minh Đường', 'Kim Quỹ', 'Thiên Đức', 'Ngọc Đường', 'Tư Mệnh'];
120
- exports.AUSPICIOUS = AUSPICIOUS;
121
- const INAUSPICIOUS = ['Thiên Hình', 'Chu Tước', 'Bạch Hổ', 'Câu Trận', 'Thiên Lao', 'Huyền Vũ'];
122
- exports.INAUSPICIOUS = INAUSPICIOUS;
123
- const ZODIAC_SIGNS = {
124
- 'Dần': ['Câu Trận', 'Thanh Long', 'Minh Đường', 'Thiên Hình', 'Chu Tước', 'Kim Quỹ', 'Bạch Hổ', 'Thiên Đức', 'Ngọc Đường', 'Thiên Lao', 'Huyền Vũ', 'Tư Mệnh'],
125
- 'Thân': ['Câu Trận', 'Thanh Long', 'Minh Đường', 'Thiên Hình', 'Chu Tước', 'Kim Quỹ', 'Bạch Hổ', 'Thiên Đức', 'Ngọc Đường', 'Thiên Lao', 'Huyền Vũ', 'Tư Mệnh'],
126
- 'Mão': ['Thanh Long', 'Minh Đường', 'Thiên Hình', 'Chu Tước', 'Kim Quỹ', 'Bạch Hổ', 'Thiên Đức', 'Ngọc Đường', 'Thiên Lao', 'Huyền Vũ', 'Tư Mệnh', 'Câu Trận'],
127
- 'Dậu': ['Thanh Long', 'Minh Đường', 'Thiên Hình', 'Chu Tước', 'Kim Quỹ', 'Bạch Hổ', 'Thiên Đức', 'Ngọc Đường', 'Thiên Lao', 'Huyền Vũ', 'Tư Mệnh', 'Câu Trận'],
128
- 'Thìn': ['Minh Đường', 'Thiên Hình', 'Chu Tước', 'Kim Quỹ', 'Bạch Hổ', 'Thiên Đức', 'Ngọc Đường', 'Thiên Lao', 'Huyền Vũ', 'Tư Mệnh', 'Câu Trận', 'Thanh Long'],
129
- 'Tuất': ['Minh Đường', 'Thiên Hình', 'Chu Tước', 'Kim Quỹ', 'Bạch Hổ', 'Thiên Đức', 'Ngọc Đường', 'Thiên Lao', 'Huyền Vũ', 'Tư Mệnh', 'Câu Trận', 'Thanh Long'],
130
- 'Tỵ': ['Thiên Hình', 'Chu Tước', 'Kim Quỹ', 'Bạch Hổ', 'Thiên Đức', 'Ngọc Đường', 'Thiên Lao', 'Huyền Vũ', 'Tư Mệnh', 'Câu Trận', 'Thanh Long', 'Minh Đường'],
131
- 'Hợi': ['Thiên Hình', 'Chu Tước', 'Kim Quỹ', 'Bạch Hổ', 'Thiên Đức', 'Ngọc Đường', 'Thiên Lao', 'Huyền Vũ', 'Tư Mệnh', 'Câu Trận', 'Thanh Long', 'Minh Đường'],
132
- 'Ngọ': ['Chu Tước', 'Kim Quỹ', 'Bạch Hổ', 'Thiên Đức', 'Ngọc Đường', 'Thiên Lao', 'Huyền Vũ', 'Tư Mệnh', 'Câu Trận', 'Thanh Long', 'Minh Đường', 'Thiên Hình'],
133
- 'Tý': ['Chu Tước', 'Kim Quỹ', 'Bạch Hổ', 'Thiên Đức', 'Ngọc Đường', 'Thiên Lao', 'Huyền Vũ', 'Tư Mệnh', 'Câu Trận', 'Thanh Long', 'Minh Đường', 'Thiên Hình'],
134
- 'Mùi': ['Kim Quỹ', 'Bạch Hổ', 'Thiên Đức', 'Ngọc Đường', 'Thiên Lao', 'Huyền Vũ', 'Tư Mệnh', 'Câu Trận', 'Thanh Long', 'Minh Đường', 'Thiên Hình', 'Chu Tước'],
135
- 'Sửu': ['Kim Quỹ', 'Bạch Hổ', 'Thiên Đức', 'Ngọc Đường', 'Thiên Lao', 'Huyền Vũ', 'Tư Mệnh', 'Câu Trận', 'Thanh Long', 'Minh Đường', 'Thiên Hình', 'Chu Tước']
136
- };
137
- exports.ZODIAC_SIGNS = ZODIAC_SIGNS;
119
+ const DAY_STARS = ['Thanh Long', 'Minh Đường', 'Thiên Hình', 'Chu Tước', 'Kim Quỹ', 'Thiên Đức', 'Bạch Hổ', 'Ngọc Đường', 'Thiên Lao', 'Huyền Vũ', 'Tư Mệnh', 'Câu Trận'];
120
+ exports.DAY_STARS = DAY_STARS;
121
+ const AUSPICIOUS_DAY_STARS = ['Thanh Long', 'Minh Đường', 'Kim Quỹ', 'Thiên Đức', 'Ngọc Đường', 'Tư Mệnh'];
122
+ exports.AUSPICIOUS_DAY_STARS = AUSPICIOUS_DAY_STARS;
138
123
  const LEAP_TEXT = ' (nhuận)';
139
124
  exports.LEAP_TEXT = LEAP_TEXT;
140
125
  const DAY_OF_WEEK = ['Chủ Nhật', 'Thứ Hai', 'Thứ Ba', 'Thứ Tư', 'Thứ Năm', 'Thứ Sáu', 'Thứ Bảy'];
141
126
  exports.DAY_OF_WEEK = DAY_OF_WEEK;
142
- const FIRST_DAY = (0, utils_1.getJulianDayNumber)(25, 1, 1800);
127
+ const FIRST_DAY = (0, utils_js_1.getJulianDayNumber)(25, 1, 1800);
143
128
  exports.FIRST_DAY = FIRST_DAY;
144
- const LAST_DAY = (0, utils_1.getJulianDayNumber)(31, 12, 2199);
129
+ const LAST_DAY = (0, utils_js_1.getJulianDayNumber)(31, 12, 2199);
145
130
  exports.LAST_DAY = LAST_DAY;
146
- const DATE_FORMAT = ["D/M/YYYY", "DD/M/YYYY", "D/MM/YYYY", "DD/MM/YYYY"];
147
- exports.DATE_FORMAT = DATE_FORMAT;
148
131
  const PI = Math.PI;
149
132
  exports.PI = PI;
@@ -0,0 +1,14 @@
1
+ import { DayStarInfo, LunarDate, StarCategory, StarSystem } from "./type.js";
2
+ type StarDefinition = {
3
+ name: string;
4
+ aliases: string[];
5
+ /** Hiệp Kỷ Biện Phương Thư: 6 hoàng đạo / 6 hắc đạo. */
6
+ hiepKy: StarCategory;
7
+ /** Ngọc Hạp Thông Thư: 4 hoàng đạo / 4 hắc đạo, 4 thần còn lại không thuộc nhóm nào. */
8
+ ngocHap: StarCategory;
9
+ };
10
+ export declare const STAR_DEFINITIONS: StarDefinition[];
11
+ export declare const getStarCategory: (starIndex: number, system: StarSystem) => StarCategory;
12
+ export declare const getHourStarPosition: (julianDay: number, hourBranch: number) => number;
13
+ export declare const getDayStarInfo: (lunarDate: LunarDate, system?: StarSystem) => DayStarInfo;
14
+ export {};
@@ -0,0 +1,64 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getDayStarInfo = exports.getHourStarPosition = exports.getStarCategory = exports.STAR_DEFINITIONS = void 0;
4
+ const constants_js_1 = require("./constants.js");
5
+ const heavenly_earthly_js_1 = require("./heavenly_earthly.js");
6
+ // Vị trí sao Thanh Long trên Chi ngày, theo Nguyệt Kiến (Chi của tháng tiết khí hiện tại).
7
+ // Suy từ "Thanh Long Hoàng Đạo Ca" (Hiệp Kỷ Biện Phương Thư):
8
+ // Dần/Thân gia Tý, Mão/Dậu khước tại Dần, Thìn/Tuất long vị thượng,
9
+ // Tỵ/Hợi ngọ thượng tồn, Tý/Ngọ lâm Thân địa, Sửu/Mùi Tuất thượng hành.
10
+ // Index = Chi tháng (Tý=0,Sửu=1,Dần=2,...,Hợi=11), value = offset Chi ngày của Thanh Long.
11
+ const THANH_LONG_OFFSET_BY_MONTH_ZHI = [8, 10, 0, 2, 4, 6, 8, 10, 0, 2, 4, 6];
12
+ // Vị trí giờ của Thanh Long theo Chi ngày (Tý/Ngọ → giờ Thân, Sửu/Mùi → Tuất, Dần/Thân → Tý, ...).
13
+ // Index = Chi ngày % 6. Khớp với bảng AUSPICIOUS_HOURS.
14
+ const THANH_LONG_HOUR_BY_DAY_ZHI = [8, 10, 0, 2, 4, 6];
15
+ // Thứ tự cố định của 12 thần, bắt đầu từ Thanh Long (index 1..12 = vị trí + 1).
16
+ exports.STAR_DEFINITIONS = [
17
+ { name: constants_js_1.DAY_STARS[0], aliases: [], hiepKy: 'hoang-dao', ngocHap: 'hoang-dao' },
18
+ { name: constants_js_1.DAY_STARS[1], aliases: [], hiepKy: 'hoang-dao', ngocHap: 'hoang-dao' },
19
+ { name: constants_js_1.DAY_STARS[2], aliases: [], hiepKy: 'hac-dao', ngocHap: null },
20
+ { name: constants_js_1.DAY_STARS[3], aliases: [], hiepKy: 'hac-dao', ngocHap: 'hac-dao' },
21
+ { name: constants_js_1.DAY_STARS[4], aliases: [], hiepKy: 'hoang-dao', ngocHap: null },
22
+ { name: constants_js_1.DAY_STARS[5], aliases: ['Bảo Quang', 'Kim Đường'], hiepKy: 'hoang-dao', ngocHap: 'hoang-dao' },
23
+ { name: constants_js_1.DAY_STARS[6], aliases: [], hiepKy: 'hac-dao', ngocHap: 'hac-dao' },
24
+ { name: constants_js_1.DAY_STARS[7], aliases: [], hiepKy: 'hoang-dao', ngocHap: 'hoang-dao' },
25
+ { name: constants_js_1.DAY_STARS[8], aliases: [], hiepKy: 'hac-dao', ngocHap: null },
26
+ { name: constants_js_1.DAY_STARS[9], aliases: ['Nguyên Vũ'], hiepKy: 'hac-dao', ngocHap: 'hac-dao' },
27
+ { name: constants_js_1.DAY_STARS[10], aliases: [], hiepKy: 'hoang-dao', ngocHap: null },
28
+ { name: constants_js_1.DAY_STARS[11], aliases: ['Câu Trần'], hiepKy: 'hac-dao', ngocHap: 'hac-dao' },
29
+ ];
30
+ const getStarCategory = (starIndex, system) => {
31
+ const def = exports.STAR_DEFINITIONS[starIndex];
32
+ if (!def)
33
+ return null;
34
+ return system === 'ngoc-hap' ? def.ngocHap : def.hiepKy;
35
+ };
36
+ exports.getStarCategory = getStarCategory;
37
+ // Vị trí (0..11) của thần trực ngày.
38
+ const getDayStarPosition = (julianDay) => {
39
+ const thanhLongChiIndex = THANH_LONG_OFFSET_BY_MONTH_ZHI[(0, heavenly_earthly_js_1.getMonthBranchIndex)(julianDay)];
40
+ return ((0, heavenly_earthly_js_1.getDayBranchIndex)(julianDay) - thanhLongChiIndex + 12) % 12;
41
+ };
42
+ // Vị trí (0..11) của thần trực giờ `hourBranch` (0 = Tý ... 11 = Hợi) của ngày.
43
+ const getHourStarPosition = (julianDay, hourBranch) => {
44
+ const start = THANH_LONG_HOUR_BY_DAY_ZHI[(0, heavenly_earthly_js_1.getDayBranchIndex)(julianDay) % 6];
45
+ return (hourBranch - start + 12) % 12;
46
+ };
47
+ exports.getHourStarPosition = getHourStarPosition;
48
+ const getDayStarInfo = (lunarDate, system = 'hiep-ky') => {
49
+ if (lunarDate.date === 0) {
50
+ return { star: '', isAuspicious: false, index: 0, category: null, system, aliases: [] };
51
+ }
52
+ const position = getDayStarPosition(lunarDate.julianDay);
53
+ const def = exports.STAR_DEFINITIONS[position];
54
+ const category = (0, exports.getStarCategory)(position, system);
55
+ return {
56
+ star: def.name,
57
+ isAuspicious: category === 'hoang-dao',
58
+ index: position + 1,
59
+ category,
60
+ system,
61
+ aliases: def.aliases.slice(),
62
+ };
63
+ };
64
+ exports.getDayStarInfo = getDayStarInfo;
@@ -0,0 +1,8 @@
1
+ import { CanChiInfo, dateFormat, LunarDate } from "./type.js";
2
+ export declare const getDayStemIndex: (julianDay: number) => number;
3
+ export declare const getDayBranchIndex: (julianDay: number) => number;
4
+ export declare const getMonthBranchIndex: (julianDay: number) => number;
5
+ export declare const getHeavenlyEarthly: (lunarDate: LunarDate) => dateFormat;
6
+ export declare const getFirstHeavenlyHour: (julianDay: number) => string;
7
+ /** Chỉ số Can (0..9) / Chi (0..11) + chuỗi của ngày, tháng (âm lịch), năm (âm lịch) và giờ Tý đầu ngày. */
8
+ export declare const getCanChi: (lunarDate: LunarDate) => CanChiInfo;
@@ -0,0 +1,57 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.getCanChi = exports.getFirstHeavenlyHour = exports.getHeavenlyEarthly = exports.getMonthBranchIndex = exports.getDayBranchIndex = exports.getDayStemIndex = void 0;
4
+ const constants_js_1 = require("./constants.js");
5
+ const utils_js_1 = require("./utils.js");
6
+ // Index of "Lập Xuân" in SOLAR_TERMS; the month branch becomes Dần from this term on.
7
+ const LAP_XUAN_TERM_INDEX = 21;
8
+ const getDayStemIndex = (julianDay) => (julianDay + 9) % 10;
9
+ exports.getDayStemIndex = getDayStemIndex;
10
+ const getDayBranchIndex = (julianDay) => (julianDay + 1) % 12;
11
+ exports.getDayBranchIndex = getDayBranchIndex;
12
+ // Month branch (Nguyệt Kiến) by solar term, not by lunar month number: Tý=0 ... Hợi=11.
13
+ const getMonthBranchIndex = (julianDay) => {
14
+ const termIndex = (0, utils_js_1.getSolarTermIndex)(julianDay);
15
+ return (Math.floor(((termIndex - LAP_XUAN_TERM_INDEX + 24) % 24) / 2) + 2) % 12;
16
+ };
17
+ exports.getMonthBranchIndex = getMonthBranchIndex;
18
+ const getYearHeavenlyEarthly = (year) => {
19
+ return constants_js_1.HEAVENLY_STEMS[(year + 6) % 10] + " " + constants_js_1.EARTHLY_BRANCHES[(year + 8) % 12];
20
+ };
21
+ const getHeavenlyEarthly = (lunarDate) => {
22
+ const { julianDay, month, year, isLeap } = lunarDate;
23
+ const dayHeavenlyEarthly = `${constants_js_1.HEAVENLY_STEMS[(0, exports.getDayStemIndex)(julianDay)]} ${constants_js_1.EARTHLY_BRANCHES[(0, exports.getDayBranchIndex)(julianDay)]}`;
24
+ const monthStemIndex = (year * 12 + month + 3) % 10;
25
+ const monthBranchIndex = (month + 1) % 12;
26
+ let monthHeavenlyEarthly = `${constants_js_1.HEAVENLY_STEMS[monthStemIndex]} ${constants_js_1.EARTHLY_BRANCHES[monthBranchIndex]}`;
27
+ if (isLeap) {
28
+ monthHeavenlyEarthly += constants_js_1.LEAP_TEXT;
29
+ }
30
+ const yearHeavenlyEarthly = getYearHeavenlyEarthly(year);
31
+ return {
32
+ date: dayHeavenlyEarthly,
33
+ month: monthHeavenlyEarthly,
34
+ year: yearHeavenlyEarthly
35
+ };
36
+ };
37
+ exports.getHeavenlyEarthly = getHeavenlyEarthly;
38
+ const getFirstHeavenlyHour = (julianDay) => {
39
+ return constants_js_1.HEAVENLY_STEMS[(julianDay - 1) * 2 % 10];
40
+ };
41
+ exports.getFirstHeavenlyHour = getFirstHeavenlyHour;
42
+ const canChiPart = (can, chi, text) => ({ can, chi, text });
43
+ /** Chỉ số Can (0..9) / Chi (0..11) + chuỗi của ngày, tháng (âm lịch), năm (âm lịch) và giờ Tý đầu ngày. */
44
+ const getCanChi = (lunarDate) => {
45
+ const { julianDay, month, year, date } = lunarDate;
46
+ const names = (0, exports.getHeavenlyEarthly)(lunarDate);
47
+ const dayCan = (0, exports.getDayStemIndex)(julianDay);
48
+ const hourCan = ((julianDay - 1) * 2) % 10;
49
+ const hasLunar = date !== 0;
50
+ return {
51
+ day: canChiPart(dayCan, (0, exports.getDayBranchIndex)(julianDay), `${constants_js_1.HEAVENLY_STEMS[dayCan]} ${constants_js_1.EARTHLY_BRANCHES[(0, exports.getDayBranchIndex)(julianDay)]}`),
52
+ month: hasLunar ? canChiPart((year * 12 + month + 3) % 10, (month + 1) % 12, String(names.month)) : canChiPart(-1, -1, ''),
53
+ year: hasLunar ? canChiPart((year + 6) % 10, (year + 8) % 12, String(names.year)) : canChiPart(-1, -1, ''),
54
+ hour: canChiPart(hourCan, 0, `${constants_js_1.HEAVENLY_STEMS[hourCan]} ${constants_js_1.EARTHLY_BRANCHES[0]}`),
55
+ };
56
+ };
57
+ exports.getCanChi = getCanChi;
@@ -0,0 +1,10 @@
1
+ import { Holiday, HolidayEvent, LunarDate } from "./type.js";
2
+ export declare const getVietnameseHolidays: (solarDay: number, solarMonth: number, solarYear: number, lunarDate: LunarDate, nextLunarDate: LunarDate) => Holiday[];
3
+ /** Mọi ngày lễ rơi vào năm dương `year`, sắp theo ngày tăng dần (lễ dương trước lễ âm nếu trùng ngày). Rỗng nếu ngoài 1800–2199. */
4
+ export declare const getHolidays: (year: number) => HolidayEvent[];
5
+ /** `count` ngày lễ tiếp theo kể từ `from` (tính cả chính ngày `from`), theo ngày tăng dần. */
6
+ export declare const nextHolidays: (from: {
7
+ day: number;
8
+ month: number;
9
+ year: number;
10
+ }, count: number) => HolidayEvent[];
@@ -0,0 +1,126 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.nextHolidays = exports.getHolidays = exports.getVietnameseHolidays = void 0;
4
+ const lunar_js_1 = require("./lunar.js");
5
+ const utils_js_1 = require("./utils.js");
6
+ const typeOf = (def, calendar) => { var _a; return def.isPublicHoliday ? 'public' : (_a = def.type) !== null && _a !== void 0 ? _a : (calendar === 'lunar' ? 'traditional' : 'commemorative'); };
7
+ const toHoliday = (def, calendar) => ({
8
+ name: def.name,
9
+ calendar,
10
+ isPublicHoliday: def.isPublicHoliday,
11
+ type: typeOf(def, calendar),
12
+ isDayOff: def.isPublicHoliday,
13
+ });
14
+ const GIAO_THUA = { name: "Giao thừa", isPublicHoliday: false };
15
+ // isPublicHoliday: ngày nghỉ hưởng nguyên lương theo Điều 112 Bộ luật Lao động 2019 (sửa đổi bởi Nghị quyết 28/2026/QH16).
16
+ // since: năm đầu tiên ngày lễ/kỷ niệm tồn tại; không ghi nhận cho các năm trước đó.
17
+ const SOLAR_HOLIDAYS = {
18
+ "1-1": { name: "Tết Dương lịch", isPublicHoliday: true },
19
+ "3-2": { name: "Ngày thành lập Đảng Cộng sản Việt Nam", isPublicHoliday: false, since: 1930 },
20
+ "27-2": { name: "Ngày Thầy thuốc Việt Nam", isPublicHoliday: false, since: 1955 },
21
+ "8-3": { name: "Ngày Quốc tế Phụ nữ", isPublicHoliday: false, since: 1910 },
22
+ "26-3": { name: "Ngày thành lập Đoàn TNCS Hồ Chí Minh", isPublicHoliday: false, since: 1931 },
23
+ "30-4": { name: "Ngày Giải phóng miền Nam, thống nhất đất nước", isPublicHoliday: true, since: 1975 },
24
+ "1-5": { name: "Ngày Quốc tế Lao động", isPublicHoliday: true, since: 1890 },
25
+ "7-5": { name: "Ngày Chiến thắng Điện Biên Phủ", isPublicHoliday: false, since: 1954 },
26
+ "19-5": { name: "Ngày sinh Chủ tịch Hồ Chí Minh", isPublicHoliday: false, since: 1890 },
27
+ "1-6": { name: "Ngày Quốc tế Thiếu nhi", isPublicHoliday: false, since: 1950 },
28
+ "28-6": { name: "Ngày Gia đình Việt Nam", isPublicHoliday: false, since: 2001 },
29
+ "27-7": { name: "Ngày Thương binh Liệt sĩ", isPublicHoliday: false, since: 1947 },
30
+ "19-8": { name: "Ngày Cách mạng tháng Tám", isPublicHoliday: false, since: 1945 },
31
+ "2-9": { name: "Ngày Quốc khánh", isPublicHoliday: true, since: 1945 },
32
+ "10-10": { name: "Ngày Giải phóng Thủ đô", isPublicHoliday: false, since: 1954 },
33
+ "20-10": { name: "Ngày Phụ nữ Việt Nam", isPublicHoliday: false, since: 1930 },
34
+ "20-11": { name: "Ngày Nhà giáo Việt Nam", isPublicHoliday: false, since: 1982 },
35
+ "24-11": { name: "Ngày Văn hóa Việt Nam", isPublicHoliday: true, since: 2026 },
36
+ "22-12": { name: "Ngày thành lập Quân đội Nhân dân Việt Nam", isPublicHoliday: false, since: 1944 },
37
+ "25-12": { name: "Lễ Giáng sinh", isPublicHoliday: false, type: 'traditional' },
38
+ };
39
+ const LUNAR_HOLIDAYS = {
40
+ "1-1": { name: "Tết Nguyên Đán", isPublicHoliday: true },
41
+ "2-1": { name: "Tết Nguyên Đán", isPublicHoliday: true },
42
+ "3-1": { name: "Tết Nguyên Đán", isPublicHoliday: true },
43
+ "15-1": { name: "Tết Nguyên Tiêu", isPublicHoliday: false },
44
+ "3-3": { name: "Tết Hàn Thực", isPublicHoliday: false },
45
+ "10-3": { name: "Giỗ Tổ Hùng Vương", isPublicHoliday: true },
46
+ "15-4": { name: "Lễ Phật Đản", isPublicHoliday: false },
47
+ "5-5": { name: "Tết Đoan Ngọ", isPublicHoliday: false },
48
+ "7-7": { name: "Tết Thất Tịch", isPublicHoliday: false },
49
+ "15-7": { name: "Lễ Vu Lan", isPublicHoliday: false },
50
+ "15-8": { name: "Tết Trung Thu", isPublicHoliday: false },
51
+ "9-9": { name: "Tết Trùng Cửu", isPublicHoliday: false },
52
+ "10-10": { name: "Tết Thường Tân", isPublicHoliday: false },
53
+ "15-10": { name: "Tết Hạ Nguyên", isPublicHoliday: false },
54
+ "23-12": { name: "Lễ cúng Ông Táo", isPublicHoliday: false },
55
+ };
56
+ const getVietnameseHolidays = (solarDay, solarMonth, solarYear, lunarDate, nextLunarDate) => {
57
+ const holidays = [];
58
+ const solarHoliday = SOLAR_HOLIDAYS[`${solarDay}-${solarMonth}`];
59
+ if (solarHoliday && (solarHoliday.since === undefined || solarYear >= solarHoliday.since)) {
60
+ holidays.push(toHoliday(solarHoliday, 'solar'));
61
+ }
62
+ // Lễ âm lịch chỉ tính cho tháng thường, tránh lặp lại ở tháng nhuận.
63
+ if (lunarDate.date !== 0 && !lunarDate.isLeap) {
64
+ const lunarHoliday = LUNAR_HOLIDAYS[`${lunarDate.date}-${lunarDate.month}`];
65
+ if (lunarHoliday) {
66
+ holidays.push(toHoliday(lunarHoliday, 'lunar'));
67
+ }
68
+ }
69
+ // Tháng Chạp có thể có 29 hoặc 30 ngày, nên Giao thừa là ngày ngay trước mùng 1 Tết.
70
+ if (nextLunarDate.date === 1 && nextLunarDate.month === 1 && !nextLunarDate.isLeap) {
71
+ holidays.push(toHoliday(GIAO_THUA, 'lunar'));
72
+ }
73
+ return holidays;
74
+ };
75
+ exports.getVietnameseHolidays = getVietnameseHolidays;
76
+ const eventOf = (def, calendar, jd, lunar) => {
77
+ const h = toHoliday(def, calendar);
78
+ const event = {
79
+ name: h.name, date: (0, utils_js_1.jdToSolarDate)(jd), calendar, type: h.type, isDayOff: h.isDayOff, isPublicHoliday: h.isPublicHoliday,
80
+ };
81
+ if (lunar)
82
+ event.lunarDate = lunar;
83
+ return event;
84
+ };
85
+ const byDate = (a, b) => (a.date.year - b.date.year) || (a.date.month - b.date.month) || (a.date.day - b.date.day);
86
+ /** Mọi ngày lễ rơi vào năm dương `year`, sắp theo ngày tăng dần (lễ dương trước lễ âm nếu trùng ngày). Rỗng nếu ngoài 1800–2199. */
87
+ const getHolidays = (year) => {
88
+ if (!Number.isInteger(year) || year < 1800 || year > 2199)
89
+ return [];
90
+ const events = [];
91
+ for (const [key, def] of Object.entries(SOLAR_HOLIDAYS)) {
92
+ if (def.since !== undefined && year < def.since)
93
+ continue;
94
+ const [day, month] = key.split('-').map(Number);
95
+ events.push(eventOf(def, 'solar', (0, utils_js_1.getJulianDayNumber)(day, month, year)));
96
+ }
97
+ // Năm âm Y-1 và Y đều có thể có ngày rơi vào năm dương Y (Ông Táo 23/12, Giao thừa).
98
+ for (const lunarYear of [year - 1, year, year + 1]) {
99
+ for (const [key, def] of Object.entries(LUNAR_HOLIDAYS)) {
100
+ const [day, month] = key.split('-').map(Number);
101
+ const solar = (0, lunar_js_1.getSolarDate)(day, month, lunarYear, false);
102
+ if (solar && solar.year === year)
103
+ events.push(eventOf(def, 'lunar', solar.jd, { day, month }));
104
+ }
105
+ const tet = (0, lunar_js_1.getSolarDate)(1, 1, lunarYear, false);
106
+ if (tet && tet.jd - 1 >= (0, utils_js_1.getJulianDayNumber)(1, 1, year) && (0, utils_js_1.jdToSolarDate)(tet.jd - 1).year === year) {
107
+ const eve = (0, lunar_js_1.getLunarDate)(...Object.values((0, utils_js_1.jdToSolarDate)(tet.jd - 1)));
108
+ events.push(eventOf(GIAO_THUA, 'lunar', tet.jd - 1, { day: eve.date, month: eve.month }));
109
+ }
110
+ }
111
+ return events.sort(byDate);
112
+ };
113
+ exports.getHolidays = getHolidays;
114
+ /** `count` ngày lễ tiếp theo kể từ `from` (tính cả chính ngày `from`), theo ngày tăng dần. */
115
+ const nextHolidays = (from, count) => {
116
+ const result = [];
117
+ const start = (0, utils_js_1.getJulianDayNumber)(from.day, from.month, from.year);
118
+ for (let year = from.year; year <= 2199 && result.length < count; year++) {
119
+ for (const e of (0, exports.getHolidays)(year)) {
120
+ if ((0, utils_js_1.getJulianDayNumber)(e.date.day, e.date.month, e.date.year) >= start)
121
+ result.push(e);
122
+ }
123
+ }
124
+ return result.slice(0, Math.max(0, count));
125
+ };
126
+ exports.nextHolidays = nextHolidays;
@@ -0,0 +1,9 @@
1
+ export { dayInfo, lunarDay, getHourInfo, monthInfo } from './lunarConverter.js';
2
+ export { getLunarDate, getSolarDate, getLeapMonth, getLunarMonthDays } from './lunar.js';
3
+ export { getJulianDayNumber, getSolarTermIndex } from './utils.js';
4
+ export { getHeavenlyEarthly, getDayStemIndex, getDayBranchIndex, getMonthBranchIndex, getCanChi, } from './heavenly_earthly.js';
5
+ export { getDayStarInfo } from './dayStar.js';
6
+ export { getSolarTerms } from './solarTerms.js';
7
+ export { getHolidays, nextHolidays } from './holidays.js';
8
+ export { HEAVENLY_STEMS, EARTHLY_BRANCHES, SOLAR_TERMS } from './constants.js';
9
+ export type { LunarDate, DayInfo, LunarDayInfo, DayStarInfo, Holiday, dateFormat, StarSystem, StarCategory, HolidayType, HolidayEvent, HourInfo, SolarTermItem, SolarTermInfo, CanChiInfo, CanChiPart, Element, DayInfoOptions, DateInput, SolarDateObject, SolarDateResult, } from './type.js';
@@ -0,0 +1,33 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.SOLAR_TERMS = exports.EARTHLY_BRANCHES = exports.HEAVENLY_STEMS = exports.nextHolidays = exports.getHolidays = exports.getSolarTerms = exports.getDayStarInfo = exports.getCanChi = exports.getMonthBranchIndex = exports.getDayBranchIndex = exports.getDayStemIndex = exports.getHeavenlyEarthly = exports.getSolarTermIndex = exports.getJulianDayNumber = exports.getLunarMonthDays = exports.getLeapMonth = exports.getSolarDate = exports.getLunarDate = exports.monthInfo = exports.getHourInfo = exports.lunarDay = exports.dayInfo = void 0;
4
+ var lunarConverter_js_1 = require("./lunarConverter.js");
5
+ Object.defineProperty(exports, "dayInfo", { enumerable: true, get: function () { return lunarConverter_js_1.dayInfo; } });
6
+ Object.defineProperty(exports, "lunarDay", { enumerable: true, get: function () { return lunarConverter_js_1.lunarDay; } });
7
+ Object.defineProperty(exports, "getHourInfo", { enumerable: true, get: function () { return lunarConverter_js_1.getHourInfo; } });
8
+ Object.defineProperty(exports, "monthInfo", { enumerable: true, get: function () { return lunarConverter_js_1.monthInfo; } });
9
+ var lunar_js_1 = require("./lunar.js");
10
+ Object.defineProperty(exports, "getLunarDate", { enumerable: true, get: function () { return lunar_js_1.getLunarDate; } });
11
+ Object.defineProperty(exports, "getSolarDate", { enumerable: true, get: function () { return lunar_js_1.getSolarDate; } });
12
+ Object.defineProperty(exports, "getLeapMonth", { enumerable: true, get: function () { return lunar_js_1.getLeapMonth; } });
13
+ Object.defineProperty(exports, "getLunarMonthDays", { enumerable: true, get: function () { return lunar_js_1.getLunarMonthDays; } });
14
+ var utils_js_1 = require("./utils.js");
15
+ Object.defineProperty(exports, "getJulianDayNumber", { enumerable: true, get: function () { return utils_js_1.getJulianDayNumber; } });
16
+ Object.defineProperty(exports, "getSolarTermIndex", { enumerable: true, get: function () { return utils_js_1.getSolarTermIndex; } });
17
+ var heavenly_earthly_js_1 = require("./heavenly_earthly.js");
18
+ Object.defineProperty(exports, "getHeavenlyEarthly", { enumerable: true, get: function () { return heavenly_earthly_js_1.getHeavenlyEarthly; } });
19
+ Object.defineProperty(exports, "getDayStemIndex", { enumerable: true, get: function () { return heavenly_earthly_js_1.getDayStemIndex; } });
20
+ Object.defineProperty(exports, "getDayBranchIndex", { enumerable: true, get: function () { return heavenly_earthly_js_1.getDayBranchIndex; } });
21
+ Object.defineProperty(exports, "getMonthBranchIndex", { enumerable: true, get: function () { return heavenly_earthly_js_1.getMonthBranchIndex; } });
22
+ Object.defineProperty(exports, "getCanChi", { enumerable: true, get: function () { return heavenly_earthly_js_1.getCanChi; } });
23
+ var dayStar_js_1 = require("./dayStar.js");
24
+ Object.defineProperty(exports, "getDayStarInfo", { enumerable: true, get: function () { return dayStar_js_1.getDayStarInfo; } });
25
+ var solarTerms_js_1 = require("./solarTerms.js");
26
+ Object.defineProperty(exports, "getSolarTerms", { enumerable: true, get: function () { return solarTerms_js_1.getSolarTerms; } });
27
+ var holidays_js_1 = require("./holidays.js");
28
+ Object.defineProperty(exports, "getHolidays", { enumerable: true, get: function () { return holidays_js_1.getHolidays; } });
29
+ Object.defineProperty(exports, "nextHolidays", { enumerable: true, get: function () { return holidays_js_1.nextHolidays; } });
30
+ var constants_js_1 = require("./constants.js");
31
+ Object.defineProperty(exports, "HEAVENLY_STEMS", { enumerable: true, get: function () { return constants_js_1.HEAVENLY_STEMS; } });
32
+ Object.defineProperty(exports, "EARTHLY_BRANCHES", { enumerable: true, get: function () { return constants_js_1.EARTHLY_BRANCHES; } });
33
+ Object.defineProperty(exports, "SOLAR_TERMS", { enumerable: true, get: function () { return constants_js_1.SOLAR_TERMS; } });
@@ -0,0 +1,5 @@
1
+ import { SolarDateObject } from "./type.js";
2
+ export declare const MIN_YEAR = 1800;
3
+ export declare const MAX_YEAR = 2199;
4
+ /** Chuẩn hóa mọi dạng đầu vào về `{day, month, year}`; `null` nếu sai định dạng, không tồn tại hoặc ngoài 1800–2199. */
5
+ export declare const parseDateInput: (input: unknown) => SolarDateObject | null;
@@ -0,0 +1,39 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.parseDateInput = exports.MAX_YEAR = exports.MIN_YEAR = void 0;
4
+ const utils_js_1 = require("./utils.js");
5
+ exports.MIN_YEAR = 1800;
6
+ exports.MAX_YEAR = 2199;
7
+ const STRING_FORMAT = /^(\d{1,2})\/(\d{1,2})\/(\d{4})$/;
8
+ const isRealDate = (day, month, year) => {
9
+ if (![day, month, year].every(Number.isInteger))
10
+ return false;
11
+ if (month < 1 || month > 12 || day < 1 || year < exports.MIN_YEAR || year > exports.MAX_YEAR)
12
+ return false;
13
+ const back = (0, utils_js_1.jdToSolarDate)((0, utils_js_1.getJulianDayNumber)(day, month, year));
14
+ return back.day === day && back.month === month && back.year === year;
15
+ };
16
+ /** Chuẩn hóa mọi dạng đầu vào về `{day, month, year}`; `null` nếu sai định dạng, không tồn tại hoặc ngoài 1800–2199. */
17
+ const parseDateInput = (input) => {
18
+ let day, month, year;
19
+ if (typeof input === 'string') {
20
+ const m = STRING_FORMAT.exec(input);
21
+ if (!m)
22
+ return null;
23
+ [day, month, year] = [Number(m[1]), Number(m[2]), Number(m[3])];
24
+ }
25
+ else if (input instanceof Date) {
26
+ if (isNaN(input.getTime()))
27
+ return null;
28
+ [day, month, year] = [input.getDate(), input.getMonth() + 1, input.getFullYear()];
29
+ }
30
+ else if (input && typeof input === 'object') {
31
+ const o = input;
32
+ [day, month, year] = [o.day, o.month, o.year];
33
+ }
34
+ else {
35
+ return null;
36
+ }
37
+ return isRealDate(day, month, year) ? { day, month, year } : null;
38
+ };
39
+ exports.parseDateInput = parseDateInput;