vietnamese-lunar 2.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 +27 -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} +1 -2
  7. package/lib/{constants.js → cjs/constants.js} +4 -6
  8. package/lib/cjs/dayStar.d.ts +14 -0
  9. package/lib/cjs/dayStar.js +64 -0
  10. package/lib/{heavenly_earthly.d.ts → cjs/heavenly_earthly.d.ts} +3 -1
  11. package/lib/cjs/heavenly_earthly.js +57 -0
  12. package/lib/cjs/holidays.d.ts +10 -0
  13. package/lib/{holidays.js → cjs/holidays.js} +67 -5
  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} +6 -0
  27. package/lib/{utils.js → cjs/utils.js} +18 -2
  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 +22 -8
  56. package/readme.md +114 -11
  57. package/lib/auspiciousHours.d.ts +0 -2
  58. package/lib/auspiciousHours.js +0 -39
  59. package/lib/dayStar.d.ts +0 -2
  60. package/lib/dayStar.js +0 -24
  61. package/lib/heavenly_earthly.js +0 -41
  62. package/lib/holidays.d.ts +0 -2
  63. package/lib/index.d.ts +0 -7
  64. package/lib/index.js +0 -22
  65. package/lib/lunar.d.ts +0 -3
  66. package/lib/lunar.js +0 -111
  67. package/lib/lunarConverter.d.ts +0 -3
  68. package/lib/lunarConverter.js +0 -67
  69. package/lib/type.d.ts +0 -45
  70. /package/lib/{type.js → cjs/type.js} +0 -0
package/CHANGELOG.md CHANGED
@@ -2,6 +2,33 @@
2
2
 
3
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
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
+
5
32
  ## 2.0.0 — 2026-10-26
6
33
 
7
34
  ### ⚠️ Breaking changes
@@ -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;
@@ -10,6 +10,5 @@ declare const LEAP_TEXT = " (nhu\u1EADn)";
10
10
  declare const DAY_OF_WEEK: string[];
11
11
  declare const FIRST_DAY: number;
12
12
  declare const LAST_DAY: number;
13
- declare const DATE_FORMAT: string[];
14
13
  declare const PI: number;
15
- 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, DAY_STARS, AUSPICIOUS_DAY_STARS };
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.AUSPICIOUS_DAY_STARS = exports.DAY_STARS = 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,
@@ -124,11 +124,9 @@ const LEAP_TEXT = ' (nhuận)';
124
124
  exports.LEAP_TEXT = LEAP_TEXT;
125
125
  const DAY_OF_WEEK = ['Chủ Nhật', 'Thứ Hai', 'Thứ Ba', 'Thứ Tư', 'Thứ Năm', 'Thứ Sáu', 'Thứ Bảy'];
126
126
  exports.DAY_OF_WEEK = DAY_OF_WEEK;
127
- const FIRST_DAY = (0, utils_1.getJulianDayNumber)(25, 1, 1800);
127
+ const FIRST_DAY = (0, utils_js_1.getJulianDayNumber)(25, 1, 1800);
128
128
  exports.FIRST_DAY = FIRST_DAY;
129
- const LAST_DAY = (0, utils_1.getJulianDayNumber)(31, 12, 2199);
129
+ const LAST_DAY = (0, utils_js_1.getJulianDayNumber)(31, 12, 2199);
130
130
  exports.LAST_DAY = LAST_DAY;
131
- const DATE_FORMAT = ["D/M/YYYY", "DD/M/YYYY", "D/MM/YYYY", "DD/MM/YYYY"];
132
- exports.DATE_FORMAT = DATE_FORMAT;
133
131
  const PI = Math.PI;
134
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;
@@ -1,6 +1,8 @@
1
- import { dateFormat, LunarDate } from "./type";
1
+ import { CanChiInfo, dateFormat, LunarDate } from "./type.js";
2
2
  export declare const getDayStemIndex: (julianDay: number) => number;
3
3
  export declare const getDayBranchIndex: (julianDay: number) => number;
4
4
  export declare const getMonthBranchIndex: (julianDay: number) => number;
5
5
  export declare const getHeavenlyEarthly: (lunarDate: LunarDate) => dateFormat;
6
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[];
@@ -1,6 +1,17 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getVietnameseHolidays = void 0;
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 };
4
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).
5
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 đó.
6
17
  const SOLAR_HOLIDAYS = {
@@ -23,7 +34,7 @@ const SOLAR_HOLIDAYS = {
23
34
  "20-11": { name: "Ngày Nhà giáo Việt Nam", isPublicHoliday: false, since: 1982 },
24
35
  "24-11": { name: "Ngày Văn hóa Việt Nam", isPublicHoliday: true, since: 2026 },
25
36
  "22-12": { name: "Ngày thành lập Quân đội Nhân dân Việt Nam", isPublicHoliday: false, since: 1944 },
26
- "25-12": { name: "Lễ Giáng sinh", isPublicHoliday: false },
37
+ "25-12": { name: "Lễ Giáng sinh", isPublicHoliday: false, type: 'traditional' },
27
38
  };
28
39
  const LUNAR_HOLIDAYS = {
29
40
  "1-1": { name: "Tết Nguyên Đán", isPublicHoliday: true },
@@ -46,19 +57,70 @@ const getVietnameseHolidays = (solarDay, solarMonth, solarYear, lunarDate, nextL
46
57
  const holidays = [];
47
58
  const solarHoliday = SOLAR_HOLIDAYS[`${solarDay}-${solarMonth}`];
48
59
  if (solarHoliday && (solarHoliday.since === undefined || solarYear >= solarHoliday.since)) {
49
- holidays.push({ name: solarHoliday.name, isPublicHoliday: solarHoliday.isPublicHoliday, calendar: 'solar' });
60
+ holidays.push(toHoliday(solarHoliday, 'solar'));
50
61
  }
51
62
  // Lễ âm lịch chỉ tính cho tháng thường, tránh lặp lại ở tháng nhuận.
52
63
  if (lunarDate.date !== 0 && !lunarDate.isLeap) {
53
64
  const lunarHoliday = LUNAR_HOLIDAYS[`${lunarDate.date}-${lunarDate.month}`];
54
65
  if (lunarHoliday) {
55
- holidays.push(Object.assign(Object.assign({}, lunarHoliday), { calendar: 'lunar' }));
66
+ holidays.push(toHoliday(lunarHoliday, 'lunar'));
56
67
  }
57
68
  }
58
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.
59
70
  if (nextLunarDate.date === 1 && nextLunarDate.month === 1 && !nextLunarDate.isLeap) {
60
- holidays.push({ name: "Giao thừa", isPublicHoliday: false, calendar: 'lunar' });
71
+ holidays.push(toHoliday(GIAO_THUA, 'lunar'));
61
72
  }
62
73
  return holidays;
63
74
  };
64
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;
@@ -0,0 +1,9 @@
1
+ import { LunarDate, SolarDateResult } from "./type.js";
2
+ export declare const getLunarDate: (day: number, month: number, year: number) => LunarDate;
3
+ /** Tháng nhuận của năm âm (1–12), hoặc 0 nếu năm không nhuận / ngoài phạm vi 1800–2199. */
4
+ export declare const getLeapMonth: (lunarYear: number) => number;
5
+ /** Số ngày của tháng âm (29 hoặc 30); `null` nếu tháng/năm không tồn tại (kể cả tháng nhuận không có trong năm đó). */
6
+ export declare const getLunarMonthDays: (lunarMonth: number, lunarYear: number, isLeap?: boolean) => 29 | 30 | null;
7
+ /** Âm → dương. Trả `null` (không throw) nếu ngày âm không tồn tại hoặc kết quả nằm ngoài dữ liệu (25/1/1800 – 31/12/2199). */
8
+ export declare const getSolarDate: (lunarDay: number, lunarMonth: number, lunarYear: number, isLeap?: boolean) => SolarDateResult | null;
9
+ export declare const getDayMaster: (date: string | number) => string;