kor-lunar 1.5.4 → 1.6.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 CHANGED
@@ -13,12 +13,13 @@
13
13
 
14
14
  ## 특징
15
15
 
16
- - **음력 ↔ 양력 변환** - `toLunar`, `toSolar`
17
- - **윤달 처리** - `isLeapMonth` 옵션
18
- - **음력 간지 출력** - 세차(`secha`), 월건(`wolgeon`), 일진(`iljin`)
16
+ - **음력 ↔ 양력 변환** `toLunar`, `toSolar`
17
+ - **LunarCalendar 클래스** 음력 날짜 연산 객체 (생성, 연산, 비교)
18
+ - **윤달 처리** `isLeapMonth` 옵션
19
+ - **음력 간지 출력** — 세차(`secha`), 월건(`wolgeon`), 일진(`iljin`)
19
20
  - 윤달인 경우 `wolgeon`은 빈 문자열로 반환됩니다
20
- - **TypeScript 지원** - 타입 정의 기본 제공
21
- - **Zero Dependencies** - 외부 의존성 없음
21
+ - **TypeScript 지원** 타입 정의 기본 제공
22
+ - **Zero Dependencies** 외부 의존성 없음
22
23
  - **CJS / ESM / UMD** — 다양한 환경에서 사용 가능
23
24
 
24
25
  - [예제 사이트](https://kahyou22.github.io/kor-lunar-js/)
@@ -39,7 +40,7 @@ npm install kor-lunar
39
40
  ### 브라우저 CDN
40
41
 
41
42
  ```html
42
- <script src="https://cdn.jsdelivr.net/npm/kor-lunar@1.5/dist/kor-lunar.min.js"></script>
43
+ <script src="https://cdn.jsdelivr.net/npm/kor-lunar@1.6/dist/kor-lunar.min.js"></script>
43
44
  ```
44
45
 
45
46
  CDN 사용 시 전역 변수 `korLunar`로 접근할 수 있습니다.
@@ -57,18 +58,21 @@ const korLunar = require("kor-lunar");
57
58
  Named export도 지원합니다:
58
59
 
59
60
  ```js
60
- import { toLunar, toSolar } from "kor-lunar";
61
+ import { toLunar, toSolar, LunarCalendar } from "kor-lunar";
61
62
  ```
62
63
 
64
+ ---
65
+
63
66
  ## 예제
64
67
 
65
68
  [예제 사이트](https://kahyou22.github.io/kor-lunar-js/)
66
69
 
70
+ ### 양력 → 음력 (`toLunar`)
71
+
67
72
  ```js
68
- import korLunar from "kor-lunar";
73
+ import { toLunar } from "kor-lunar";
69
74
 
70
- // 양력 → 음력
71
- console.log(korLunar.toLunar(2025, 6, 25));
75
+ console.log(toLunar(2025, 6, 25));
72
76
  // {
73
77
  // year: 2025,
74
78
  // month: 6,
@@ -80,9 +84,12 @@ console.log(korLunar.toLunar(2025, 6, 25));
80
84
  // julianDay: 2460852,
81
85
  // dayOfWeek: 3
82
86
  // }
87
+ ```
83
88
 
84
- // 양력 → 음력 (윤달)
85
- console.log(korLunar.toLunar(2025, 7, 25));
89
+ ### 양력 → 음력 (윤달)
90
+
91
+ ```js
92
+ console.log(toLunar(2025, 7, 25));
86
93
  // {
87
94
  // year: 2025,
88
95
  // month: 6,
@@ -94,12 +101,17 @@ console.log(korLunar.toLunar(2025, 7, 25));
94
101
  // julianDay: 2460882,
95
102
  // dayOfWeek: 5
96
103
  // }
104
+ ```
97
105
 
98
- // 음력 → 양력
99
- console.log(korLunar.toSolar(2025, 6, 1, false));
106
+ ### 음력 → 양력 (`toSolar`)
107
+
108
+ ```js
109
+ import { toSolar } from "kor-lunar";
110
+
111
+ console.log(toSolar(2025, 6, 1, false));
100
112
  // { year: 2025, month: 6, day: 25 }
101
113
 
102
- console.log(korLunar.toSolar(2025, 6, 1, true));
114
+ console.log(toSolar(2025, 6, 1, true));
103
115
  // { year: 2025, month: 7, day: 25 }
104
116
  ```
105
117
 
@@ -107,6 +119,78 @@ console.log(korLunar.toSolar(2025, 6, 1, true));
107
119
  > 이를 통해 단순 음력 변환 뿐만 아니라, 더 다양한 기능을 구현할 수 있습니다.
108
120
  > [예제 사이트: 음력 달력](https://kahyou22.github.io/kor-lunar-js/#lunarCalendar)
109
121
 
122
+ ---
123
+
124
+ ## LunarCalendar
125
+
126
+ 음력 날짜를 다루기 위한 **불변(immutable) 클래스**입니다.
127
+ 날짜 연산, 비교, 변환 등을 지원하며, 모든 변경 메서드는 원본을 수정하지 않고 새 객체를 반환합니다.
128
+
129
+ ### 예제
130
+
131
+ ```js
132
+ import { LunarCalendar } from "kor-lunar";
133
+
134
+ // 음력 날짜로 생성 (2025년 8월 15일, 추석)
135
+ const chuseok = LunarCalendar.of(2025, 8, 15);
136
+
137
+ // 속성 접근
138
+ chuseok.year; // 2025
139
+ chuseok.month; // 8
140
+ chuseok.day; // 15
141
+ chuseok.isLeapMonth; // false
142
+ chuseok.dayOfWeek; // 0 (일요일)
143
+ chuseok.secha; // '을사'
144
+ chuseok.wolgeon; // '을유'
145
+ chuseok.iljin; // '무신'
146
+
147
+ // 양력 변환
148
+ chuseok.toSolar(); // { year: 2025, month: 10, day: 6 }
149
+
150
+ // 문자열 표현
151
+ chuseok.toString(); // '2025-08-15' (윤달인 경우 2025-윤06-01)
152
+
153
+ // 날짜 연산 (원본은 변경되지 않음)
154
+ const nextDay = chuseok.addDays(1);
155
+ const nextMonth = chuseok.addMonths(1);
156
+ const nextYear = chuseok.addYears(1);
157
+
158
+ // 비교
159
+ chuseok.isBefore(nextDay); // true
160
+ chuseok.equals(chuseok); // true
161
+ nextDay.diffDays(chuseok); // 1
162
+ ```
163
+
164
+ #### addMonths 동작 방식
165
+
166
+ - 윤달도 하나의 독립적인 월로 취급합니다
167
+ - 대상 월의 일수가 현재 일보다 적으면 마지막 날로 클램핑됩니다
168
+
169
+ ```js
170
+ // 2025년에는 윤6월이 있음
171
+ const june = LunarCalendar.of(2025, 6, 1); // 6월 평달
172
+ const leapJune = june.addMonths(1); // 6월 윤달
173
+ const july = june.addMonths(2); // 7월 평달
174
+
175
+ // day 클램핑: 1월 30일 + 1개월 -> 2월의 마지막 날
176
+ const jan30 = LunarCalendar.of(2025, 1, 30);
177
+ const feb = jan30.addMonths(1);
178
+ feb.day; // 29 (2025년 음력 2월이 29일까지인 경우)
179
+ ```
180
+
181
+ #### addYears 동작 방식
182
+
183
+ - 같은 월/일을 유지하려 시도합니다
184
+ - 윤달인데 대상 연도에 해당 윤달이 없으면 평달로 폴백합니다
185
+ - 대상 월의 일수가 현재 일보다 적으면 마지막 날로 클램핑됩니다
186
+
187
+ ```js
188
+ // 윤달 → 대상 연도에 해당 윤달이 없으면 평달로
189
+ const leapJune = LunarCalendar.of(2025, 6, 1, true);
190
+ const nextYear = leapJune.addYears(1);
191
+ nextYear.isLeapMonth; // false (2026년에 윤6월이 없으므로 평달)
192
+ ```
193
+
110
194
  ## 라이선스
111
195
 
112
196
  [MIT](LICENSE)