lichta 1.0.0-beta → 1.0.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/README.md +72 -68
- package/package.json +18 -5
package/README.md
CHANGED
|
@@ -1,28 +1,32 @@
|
|
|
1
1
|
# 🌙 LichTa
|
|
2
2
|
|
|
3
|
-
**
|
|
3
|
+
**Vietnamese Solar ↔ Lunar Calendar conversion library for JavaScript/TypeScript.**
|
|
4
4
|
|
|
5
|
-
|
|
5
|
+
Supports ready-to-use Svelte 5 components, while exporting a pure TypeScript core for React, Vue, Angular, and vanilla JS.
|
|
6
6
|
|
|
7
7
|
[](https://www.npmjs.com/package/lichta)
|
|
8
|
-
[](https://github.com/
|
|
8
|
+
[](https://github.com/zeforc/lichta/blob/main/LICENSE)
|
|
9
|
+
|
|
10
|
+
🚀 **[Live Demo](https://lich-ta.vercel.app/)**
|
|
11
|
+
|
|
12
|
+
> 🇻🇳 [Phiên bản Tiếng Việt (Vietnamese version)](./README.vi.md)
|
|
9
13
|
|
|
10
14
|
---
|
|
11
15
|
|
|
12
|
-
## ✨
|
|
16
|
+
## ✨ Features
|
|
13
17
|
|
|
14
|
-
- 🔄 **
|
|
15
|
-
- 🐉 **Can Chi** —
|
|
16
|
-
- 🔮 **Ngũ Hành
|
|
17
|
-
- ⏰ **Giờ Hoàng Đạo** — 6
|
|
18
|
-
- 📅 **Calendar Component** —
|
|
19
|
-
- 🎨 **Format** —
|
|
20
|
-
- 🌐 **i18n** —
|
|
18
|
+
- 🔄 **Solar ↔ Lunar Conversion** — Ho Ngoc Duc algorithm (range 1800–2199)
|
|
19
|
+
- 🐉 **Sexagenary Cycle (Can Chi)** — Calculate Can Chi for year, month, day, and hour
|
|
20
|
+
- 🔮 **Five Elements (Ngũ Hành)** — Calculate destiny element based on birth year
|
|
21
|
+
- ⏰ **Auspicious Hours (Giờ Hoàng Đạo)** — 6 auspicious hours in a day
|
|
22
|
+
- 📅 **Calendar Component** — Svelte 5 monthly calendar with lunar dates
|
|
23
|
+
- 🎨 **Format** — Display traditional lunar dates (Mùng Một tháng Giêng...)
|
|
24
|
+
- 🌐 **i18n** — Vietnamese–English–Japanese–Korean support (vi, en, ja, ko)
|
|
21
25
|
- 📦 **Multi-framework** — Svelte 5, React, Vue, Angular, vanilla JS
|
|
22
26
|
|
|
23
27
|
---
|
|
24
28
|
|
|
25
|
-
## 📦
|
|
29
|
+
## 📦 Installation
|
|
26
30
|
|
|
27
31
|
```bash
|
|
28
32
|
npm install lichta
|
|
@@ -30,16 +34,16 @@ npm install lichta
|
|
|
30
34
|
|
|
31
35
|
---
|
|
32
36
|
|
|
33
|
-
## 🚀
|
|
37
|
+
## 🚀 Usage
|
|
34
38
|
|
|
35
|
-
### Core Logic (
|
|
39
|
+
### Core Logic (Any framework)
|
|
36
40
|
|
|
37
|
-
Import
|
|
41
|
+
Import from `lichta/core` to use **pure TypeScript** — no Svelte dependency:
|
|
38
42
|
|
|
39
43
|
```typescript
|
|
40
44
|
import { LichTa, getYearDetails } from 'lichta/core';
|
|
41
45
|
|
|
42
|
-
//
|
|
46
|
+
// Solar → Lunar
|
|
43
47
|
const lunar = LichTa.toLunar(10, 2, 2024);
|
|
44
48
|
// → {
|
|
45
49
|
// day: 1, month: 1, year: 2024,
|
|
@@ -50,56 +54,56 @@ const lunar = LichTa.toLunar(10, 2, 2024);
|
|
|
50
54
|
// jd: 2460350
|
|
51
55
|
// }
|
|
52
56
|
|
|
53
|
-
//
|
|
57
|
+
// Lunar → Solar
|
|
54
58
|
const solar = LichTa.toSolar(1, 1, 2024, false);
|
|
55
59
|
// → { day: 10, month: 2, year: 2024 }
|
|
56
60
|
|
|
57
|
-
//
|
|
61
|
+
// Custom timezone (default is GMT+7)
|
|
58
62
|
const lunarChina = LichTa.toLunar(10, 2, 2024, 8); // GMT+8
|
|
59
63
|
```
|
|
60
64
|
|
|
61
|
-
### Can Chi & Phong Thủy
|
|
65
|
+
### Sexagenary Cycle & Feng Shui (Can Chi & Phong Thủy)
|
|
62
66
|
|
|
63
67
|
```typescript
|
|
64
68
|
import { getYearDetails, getDayCanChi, getMonthCanChi, getHourCanChi, getAuspiciousHours } from 'lichta/core';
|
|
65
69
|
|
|
66
|
-
// Can Chi +
|
|
70
|
+
// Can Chi + Element for the year
|
|
67
71
|
getYearDetails(2024);
|
|
68
72
|
// → { can: 'Giáp', chi: 'Thìn', menh: 'Hỏa',
|
|
69
73
|
// fullString: 'Giáp Thìn - Mệnh Hỏa' }
|
|
70
74
|
|
|
71
|
-
// Can Chi
|
|
75
|
+
// Day Can Chi (requires Julian Day Number)
|
|
72
76
|
const lunar = LichTa.toLunar(10, 2, 2024);
|
|
73
77
|
getDayCanChi(lunar.jd); // → 'Giáp Tý'
|
|
74
78
|
|
|
75
|
-
// Can Chi
|
|
76
|
-
getMonthCanChi(1, 2024); // →
|
|
79
|
+
// Month Can Chi
|
|
80
|
+
getMonthCanChi(1, 2024); // → month Giêng year Giáp Thìn
|
|
77
81
|
|
|
78
|
-
// Can Chi
|
|
79
|
-
getHourCanChi(8, lunar.jd); // →
|
|
82
|
+
// Hour Can Chi
|
|
83
|
+
getHourCanChi(8, lunar.jd); // → hour Thìn (7h-9h)
|
|
80
84
|
|
|
81
|
-
//
|
|
85
|
+
// Auspicious Hours
|
|
82
86
|
getAuspiciousHours(lunar.jd);
|
|
83
87
|
// → ['Tý', 'Sửu', 'Mão', 'Ngọ', 'Mùi', 'Dậu']
|
|
84
88
|
```
|
|
85
89
|
|
|
86
|
-
### Format &
|
|
90
|
+
### Format & Display
|
|
87
91
|
|
|
88
92
|
```typescript
|
|
89
93
|
import { formatTraditional, formatLunarDate, getMonthName, getDayName } from 'lichta/utils';
|
|
90
94
|
|
|
91
95
|
const lunar = LichTa.toLunar(10, 2, 2024);
|
|
92
96
|
|
|
93
|
-
//
|
|
97
|
+
// Traditional format
|
|
94
98
|
formatTraditional(lunar);
|
|
95
99
|
// → 'Mùng Một tháng Giêng năm Giáp Thìn'
|
|
96
100
|
|
|
97
|
-
//
|
|
101
|
+
// Pattern format
|
|
98
102
|
formatLunarDate(lunar, 'dd/MM/yyyy'); // → '01/01/2024'
|
|
99
103
|
formatLunarDate(lunar, 'CC'); // → 'Giáp Thìn'
|
|
100
104
|
formatLunarDate(lunar, 'Ngày DC'); // → 'Ngày Giáp Tý'
|
|
101
105
|
|
|
102
|
-
//
|
|
106
|
+
// Traditional names
|
|
103
107
|
getMonthName(1); // → 'Giêng'
|
|
104
108
|
getMonthName(12); // → 'Chạp'
|
|
105
109
|
getDayName(1); // → 'Mùng Một'
|
|
@@ -109,18 +113,18 @@ getDayName(30); // → 'Ba Mươi'
|
|
|
109
113
|
|
|
110
114
|
**Format tokens:**
|
|
111
115
|
|
|
112
|
-
| Token |
|
|
116
|
+
| Token | Description | Example |
|
|
113
117
|
|--------|-------------------------------|--------------|
|
|
114
|
-
| `dd` |
|
|
115
|
-
| `d` |
|
|
116
|
-
| `MM` |
|
|
117
|
-
| `M` |
|
|
118
|
-
| `yyyy` |
|
|
119
|
-
| `yy` |
|
|
120
|
-
| `CC` | Can Chi
|
|
121
|
-
| `DC` | Can Chi
|
|
122
|
-
| `MC` | Can Chi
|
|
123
|
-
| `L` | "Nhuận"
|
|
118
|
+
| `dd` | 2-digit day | 01, 15 |
|
|
119
|
+
| `d` | Day | 1, 15 |
|
|
120
|
+
| `MM` | 2-digit month | 01, 12 |
|
|
121
|
+
| `M` | Month | 1, 12 |
|
|
122
|
+
| `yyyy` | 4-digit year | 2024 |
|
|
123
|
+
| `yy` | Last 2 digits of year | 24 |
|
|
124
|
+
| `CC` | Year Can Chi | Giáp Thìn |
|
|
125
|
+
| `DC` | Day Can Chi | Giáp Tý |
|
|
126
|
+
| `MC` | Month Can Chi | Bính Dần |
|
|
127
|
+
| `L` | "Nhuận" if leap month | Nhuận |
|
|
124
128
|
|
|
125
129
|
### Svelte 5 Components
|
|
126
130
|
|
|
@@ -129,32 +133,32 @@ getDayName(30); // → 'Ba Mươi'
|
|
|
129
133
|
import { Calendar, Formatter } from 'lichta';
|
|
130
134
|
</script>
|
|
131
135
|
|
|
132
|
-
<!--
|
|
136
|
+
<!-- Full monthly calendar -->
|
|
133
137
|
<Calendar
|
|
134
138
|
showLunar={true}
|
|
135
139
|
locale="vi"
|
|
136
140
|
onSelect={(date, lunar) => console.log(date, lunar)}
|
|
137
141
|
/>
|
|
138
142
|
|
|
139
|
-
<!--
|
|
143
|
+
<!-- Lunar date formatter -->
|
|
140
144
|
<Formatter date={new Date()} />
|
|
141
145
|
```
|
|
142
146
|
|
|
143
147
|
#### Calendar Props
|
|
144
148
|
|
|
145
|
-
| Prop | Type |
|
|
149
|
+
| Prop | Type | Default | Description |
|
|
146
150
|
|----------------|-----------------------------------------------|-------------------|-------------------------------|
|
|
147
|
-
| `month` | `number` |
|
|
148
|
-
| `year` | `number` |
|
|
149
|
-
| `selectedDate` | `Date \| null` | `null` |
|
|
150
|
-
| `onSelect` | `(date: Date, lunar: LunarDate) => void` | — | Callback
|
|
151
|
-
| `showLunar` | `boolean` | `true` |
|
|
152
|
-
| `locale` | `'vi' \| 'en' \| 'ja' \| 'ko'` | `'vi'` |
|
|
153
|
-
| `dayCell` | `Snippet` | — | Custom snippet
|
|
151
|
+
| `month` | `number` | Current month | Displayed month (1-12) |
|
|
152
|
+
| `year` | `number` | Current year | Displayed year |
|
|
153
|
+
| `selectedDate` | `Date \| null` | `null` | Selected date |
|
|
154
|
+
| `onSelect` | `(date: Date, lunar: LunarDate) => void` | — | Callback on date select |
|
|
155
|
+
| `showLunar` | `boolean` | `true` | Show lunar dates |
|
|
156
|
+
| `locale` | `'vi' \| 'en' \| 'ja' \| 'ko'` | `'vi'` | Language |
|
|
157
|
+
| `dayCell` | `Snippet` | — | Custom snippet for day cell |
|
|
154
158
|
|
|
155
159
|
#### Theming
|
|
156
160
|
|
|
157
|
-
Calendar
|
|
161
|
+
The Calendar supports CSS custom properties:
|
|
158
162
|
|
|
159
163
|
```css
|
|
160
164
|
:root {
|
|
@@ -174,7 +178,7 @@ Calendar hỗ trợ CSS custom properties:
|
|
|
174
178
|
```typescript
|
|
175
179
|
import { t, getZodiacAnimal } from 'lichta';
|
|
176
180
|
|
|
177
|
-
//
|
|
181
|
+
// Get dictionary
|
|
178
182
|
const vi = t('vi');
|
|
179
183
|
vi.heavenlyStems; // ['Giáp', 'Ất', ...]
|
|
180
184
|
vi.earthlyBranches; // ['Tý', 'Sửu', ...]
|
|
@@ -191,7 +195,7 @@ ja.weekDays; // ['日', '月', '火', '水', '木', '金', '土']
|
|
|
191
195
|
const ko = t('ko');
|
|
192
196
|
ko.fiveElements; // ['금', '목', '수', '화', '토']
|
|
193
197
|
|
|
194
|
-
//
|
|
198
|
+
// Zodiac animal by year
|
|
195
199
|
getZodiacAnimal(0, 'vi'); // → 'Chuột'
|
|
196
200
|
getZodiacAnimal(4, 'en'); // → 'Dragon'
|
|
197
201
|
getZodiacAnimal(0, 'ja'); // → '鼠'
|
|
@@ -201,35 +205,35 @@ getZodiacAnimal(0, 'ja'); // → '鼠'
|
|
|
201
205
|
|
|
202
206
|
## 📁 Import Paths
|
|
203
207
|
|
|
204
|
-
| Path |
|
|
208
|
+
| Path | Content | Used for |
|
|
205
209
|
|-----------------|-----------------------------------|-------------------------------|
|
|
206
|
-
| `lichta` |
|
|
210
|
+
| `lichta` | Full API + Svelte components | Svelte 5 projects |
|
|
207
211
|
| `lichta/core` | Pure TypeScript logic | React, Vue, Angular, vanilla |
|
|
208
|
-
| `lichta/utils` | Format utilities |
|
|
212
|
+
| `lichta/utils` | Format utilities | Any framework |
|
|
209
213
|
|
|
210
214
|
```typescript
|
|
211
|
-
// Svelte 5 — import
|
|
215
|
+
// Svelte 5 — import everything
|
|
212
216
|
import { LichTa, Calendar, Formatter, formatTraditional } from 'lichta';
|
|
213
217
|
|
|
214
|
-
// React / Vue / Angular —
|
|
218
|
+
// React / Vue / Angular — import core logic only
|
|
215
219
|
import { LichTa, getYearDetails } from 'lichta/core';
|
|
216
220
|
import { formatTraditional, getDayName } from 'lichta/utils';
|
|
217
221
|
```
|
|
218
222
|
|
|
219
223
|
---
|
|
220
224
|
|
|
221
|
-
## 📐
|
|
225
|
+
## 📐 Algorithm
|
|
222
226
|
|
|
223
|
-
LichTa
|
|
227
|
+
LichTa uses the lunar conversion algorithm by **Ho Ngoc Duc** (Leipzig University), based on:
|
|
224
228
|
|
|
225
|
-
- **Julian Day Number** —
|
|
226
|
-
-
|
|
227
|
-
- **
|
|
228
|
-
- **Jean Meeus, "Astronomical Algorithms"** —
|
|
229
|
+
- **Julian Day Number** — Continuous day coordinate system for astronomical calculations
|
|
230
|
+
- **New Moon** — Determines the 1st day of the lunar month
|
|
231
|
+
- **Solar Terms** — Determines months and leap months
|
|
232
|
+
- **Jean Meeus, "Astronomical Algorithms"** — Precise astronomical formulas
|
|
229
233
|
|
|
230
|
-
**
|
|
234
|
+
**Range**: 1800 – 2199 | **Default timezone**: GMT+7 (Vietnam)
|
|
231
235
|
|
|
232
|
-
|
|
236
|
+
See details in [docs/ALGORITHM.md](./docs/ALGORITHM.md).
|
|
233
237
|
|
|
234
238
|
---
|
|
235
239
|
|
|
@@ -241,5 +245,5 @@ Xem chi tiết trong [docs/ALGORITHM.md](./docs/ALGORITHM.md).
|
|
|
241
245
|
|
|
242
246
|
## 🙏 Credits
|
|
243
247
|
|
|
244
|
-
- **
|
|
248
|
+
- **Ho Ngoc Duc** — Original algorithm ([informatik.uni-leipzig.de](http://www.informatik.uni-leipzig.de/~duc/amlich/))
|
|
245
249
|
- **Jean Meeus** — *Astronomical Algorithms* (1998)
|
package/package.json
CHANGED
|
@@ -1,8 +1,8 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "lichta",
|
|
3
|
-
"version": "1.0.0
|
|
3
|
+
"version": "1.0.0",
|
|
4
4
|
"description": "Thư viện chuyển đổi Dương lịch ↔ Âm lịch Việt Nam. Vietnamese lunar calendar conversion library with Svelte 5 components.",
|
|
5
|
-
"author": "
|
|
5
|
+
"author": "Zeforc | Stridev",
|
|
6
6
|
"license": "MIT",
|
|
7
7
|
"scripts": {
|
|
8
8
|
"dev": "vite dev",
|
|
@@ -62,6 +62,9 @@
|
|
|
62
62
|
"eslint-config-prettier": "^10.1.8",
|
|
63
63
|
"eslint-plugin-svelte": "^3.19.0",
|
|
64
64
|
"globals": "^17.6.0",
|
|
65
|
+
"lichta-event-calendar": "^1.0.0",
|
|
66
|
+
"lichta-full-calendar": "^1.0.0",
|
|
67
|
+
"lichta-react-big-calendar": "^1.0.0",
|
|
65
68
|
"prettier": "^3.8.3",
|
|
66
69
|
"prettier-plugin-svelte": "^4.1.0",
|
|
67
70
|
"publint": "^0.3.21",
|
|
@@ -85,10 +88,20 @@
|
|
|
85
88
|
],
|
|
86
89
|
"repository": {
|
|
87
90
|
"type": "git",
|
|
88
|
-
"url": "git+https://github.com/
|
|
91
|
+
"url": "git+https://github.com/zeforc/lichta.git"
|
|
89
92
|
},
|
|
90
93
|
"bugs": {
|
|
91
|
-
"url": "https://github.com/
|
|
94
|
+
"url": "https://github.com/zeforc/lichta/issues"
|
|
92
95
|
},
|
|
93
|
-
"homepage": "https://github.com/
|
|
96
|
+
"homepage": "https://github.com/zeforc/lichta#readme",
|
|
97
|
+
"dependencies": {
|
|
98
|
+
"@event-calendar/core": "^5.7.1",
|
|
99
|
+
"@event-calendar/day-grid": "^3.12.0",
|
|
100
|
+
"@fullcalendar/core": "^6.1.20",
|
|
101
|
+
"@fullcalendar/daygrid": "^6.1.20",
|
|
102
|
+
"moment": "^2.30.1",
|
|
103
|
+
"react": "^19.2.7",
|
|
104
|
+
"react-big-calendar": "^1.20.0",
|
|
105
|
+
"react-dom": "^19.2.7"
|
|
106
|
+
}
|
|
94
107
|
}
|