@hyunbinseo/holidays-kr 5.2027.0 → 5.2027.1
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 +9 -5
- package/dist/index.d.ts +5 -2
- package/dist/index.js +17 -4
- package/package.json +1 -1
package/README.md
CHANGED
|
@@ -2,8 +2,8 @@
|
|
|
2
2
|
|
|
3
3
|
우주항공청에서 발표한 월력요항을 사용합니다. [English](#usage)
|
|
4
4
|
|
|
5
|
-
- `Date`
|
|
6
|
-
- `CSV`, `JSON`, `ICS
|
|
5
|
+
- `Date` 객체 또는 `YYYY-MM-DD` 날짜 문자열의 공휴일 여부와 그 명칭들을 확인합니다
|
|
6
|
+
- `CSV`, `JSON`, `ICS` 파일(호스팅) 및 구독할 수 있는 캘린더 URL도 제공됩니다. [링크](https://github.com/hyunbinseo/holidays-kr#readme)
|
|
7
7
|
|
|
8
8
|
API는 연도별 공휴일 정보를 동적으로 불러오며, 데이터가 존재하지 않으면 `RangeError`를 던집니다.
|
|
9
9
|
|
|
@@ -11,12 +11,14 @@ API는 연도별 공휴일 정보를 동적으로 불러오며, 데이터가 존
|
|
|
11
11
|
import { getHolidayNames, isHoliday } from '@hyunbinseo/holidays-kr';
|
|
12
12
|
|
|
13
13
|
// 공휴일 여부
|
|
14
|
-
await isHoliday(new Date('2026-01-01T00:00:00+0900')); // true
|
|
15
14
|
await isHoliday(new Date('2026-01-02T00:00:00+0900')); // false
|
|
15
|
+
await isHoliday(new Date('2026-01-01T00:00:00+0900')); // true
|
|
16
|
+
await isHoliday('2026-01-01'); // true
|
|
16
17
|
|
|
17
18
|
// 공휴일 명칭(들)
|
|
18
|
-
await getHolidayNames(new Date('2026-05-05T00:00:00+0900')); // ['어린이날']
|
|
19
19
|
await getHolidayNames(new Date('2026-05-04T00:00:00+0900')); // null
|
|
20
|
+
await getHolidayNames(new Date('2026-05-05T00:00:00+0900')); // ['어린이날']
|
|
21
|
+
await getHolidayNames('2026-05-05'); // ['어린이날']
|
|
20
22
|
```
|
|
21
23
|
|
|
22
24
|
```js
|
|
@@ -47,6 +49,7 @@ import { isHoliday } from '@hyunbinseo/holidays-kr';
|
|
|
47
49
|
|
|
48
50
|
// Jan 01 2026 00:00:00 GMT+0900 is a holiday in ROK
|
|
49
51
|
await isHoliday(new Date('2026-01-01T00:00:00+0900')); // true
|
|
52
|
+
await isHoliday('2026-01-01'); // true
|
|
50
53
|
|
|
51
54
|
// Be cautious with the date's time zone!
|
|
52
55
|
// Dec 31 2025 23:00:00 GMT+0900 is not a holiday in ROK
|
|
@@ -56,8 +59,9 @@ await isHoliday(new Date('2026-01-01T00:00:00+1000')); // false
|
|
|
56
59
|
```js
|
|
57
60
|
import { getHolidayNames } from '@hyunbinseo/holidays-kr';
|
|
58
61
|
|
|
59
|
-
await getHolidayNames(new Date('2026-05-05T00:00:00+0900')); // ['어린이날']
|
|
60
62
|
await getHolidayNames(new Date('2026-05-04T00:00:00+0900')); // null
|
|
63
|
+
await getHolidayNames(new Date('2026-05-05T00:00:00+0900')); // ['어린이날']
|
|
64
|
+
await getHolidayNames('2026-05-05'); // ['어린이날']
|
|
61
65
|
```
|
|
62
66
|
|
|
63
67
|
```js
|
package/dist/index.d.ts
CHANGED
|
@@ -1,6 +1,9 @@
|
|
|
1
1
|
//#region src/holidays/utils.d.ts
|
|
2
|
+
type DateLike = Date | string;
|
|
3
|
+
//#endregion
|
|
4
|
+
//#region src/holidays/index.d.ts
|
|
2
5
|
declare const getHolidayPreset: (yyyy: string) => Promise<Readonly<Record<`${number}-${number}-${number}`, readonly string[]>>>;
|
|
3
|
-
declare const getHolidayNames: (
|
|
4
|
-
declare const isHoliday: (
|
|
6
|
+
declare const getHolidayNames: (input: DateLike) => Promise<readonly string[] | null>;
|
|
7
|
+
declare const isHoliday: (input: DateLike) => Promise<boolean>;
|
|
5
8
|
//#endregion
|
|
6
9
|
export { getHolidayNames, getHolidayPreset, isHoliday };
|
package/dist/index.js
CHANGED
|
@@ -1,5 +1,19 @@
|
|
|
1
1
|
//#region src/holidays/utils.ts
|
|
2
2
|
const KST_OFFSET = 540 * 6e4;
|
|
3
|
+
const ISO_DATE_REGEX = /^\d{4}-(?:0[1-9]|1[0-2])-(?:[12]\d|0[1-9]|3[01])$/u;
|
|
4
|
+
const toISODate = (input) => {
|
|
5
|
+
if (typeof input === "string") {
|
|
6
|
+
if (ISO_DATE_REGEX.test(input)) return input;
|
|
7
|
+
throw new TypeError(`Invalid date string: ${input}`);
|
|
8
|
+
}
|
|
9
|
+
if (input instanceof Date) {
|
|
10
|
+
if (isNaN(input.valueOf())) throw new RangeError("Invalid date");
|
|
11
|
+
return new Date(input.valueOf() + KST_OFFSET).toISOString().slice(0, 10);
|
|
12
|
+
}
|
|
13
|
+
throw new Error();
|
|
14
|
+
};
|
|
15
|
+
//#endregion
|
|
16
|
+
//#region src/holidays/index.ts
|
|
3
17
|
const holidayPresets = /* #__PURE__ */ Object.assign({
|
|
4
18
|
"./2018.ts": () => import("./2018-CHZjwTM_.js").then((n) => n.t).then((m) => m["default"]),
|
|
5
19
|
"./2019.ts": () => import("./2019-_6NrILve.js").then((n) => n.t).then((m) => m["default"]),
|
|
@@ -17,11 +31,10 @@ const getHolidayPreset = async (yyyy) => {
|
|
|
17
31
|
if (!loader) throw new RangeError(`No preset for year ${yyyy}`);
|
|
18
32
|
return loader();
|
|
19
33
|
};
|
|
20
|
-
const getHolidayNames = async (
|
|
21
|
-
|
|
22
|
-
const yyyy_mm_dd = new Date(date.valueOf() + KST_OFFSET).toISOString().slice(0, 10);
|
|
34
|
+
const getHolidayNames = async (input) => {
|
|
35
|
+
const yyyy_mm_dd = toISODate(input);
|
|
23
36
|
return (await getHolidayPreset(yyyy_mm_dd.slice(0, 4)))[yyyy_mm_dd] ?? null;
|
|
24
37
|
};
|
|
25
|
-
const isHoliday = async (
|
|
38
|
+
const isHoliday = async (input) => !!await getHolidayNames(input);
|
|
26
39
|
//#endregion
|
|
27
40
|
export { getHolidayNames, getHolidayPreset, isHoliday };
|