@kokr/date
Version:
Provides utilities for Korean dates. 날짜 관련 유틸리티를 제공합니다. 공휴일, 절기, 그리고 잡절 정보를 확인하고, 영업일 기준 날짜 계산을 지원합니다.
30 lines (29 loc) • 1.17 kB
JavaScript
import * as dntShim from "./_dnt.shims.js";
/** 공휴일의 종류, Holiday 공휴일 */
export var DateKind;
(function (DateKind) {
/** 공휴일 - (예) 설날, 대통령선거일, 추석 (대체공휴일) .. */
DateKind[DateKind["Holiday"] = 1] = "Holiday";
/** 기념일 - (예) 스승의 날, 국군의 날 .. */
DateKind[DateKind["Anniversary"] = 2] = "Anniversary";
/** 24절기 - (예) 입춘, 경칩 .. */
DateKind[DateKind["SolarTerms"] = 3] = "SolarTerms";
/** 잡절 - (예) 정월대보름, 초복, 중복 .. */
DateKind[DateKind["Sundry"] = 4] = "Sundry";
})(DateKind || (DateKind = {}));
const defaultHolidayUri = [
(year) => `https://holidays.dist.be/${year}.json`,
(year) => `https://cdn.jsdelivr.net/gh/distbe/holidays@gh-pages/${year}.json`,
];
export async function getHolidaysFromHttp(year, options) {
const uris = options?.uris ?? defaultHolidayUri;
if (uris.length === 0) {
return [];
}
const uri = uris[Math.random() * uris.length | 0](year);
const response = await dntShim.fetch(uri);
if (response.status === 200) {
return response.json();
}
return [];
}