Skip to content

Commit

Permalink
feat: support ESM
Browse files Browse the repository at this point in the history
  • Loading branch information
sixmen committed Jul 19, 2023
1 parent c025a8b commit 2e5268d
Show file tree
Hide file tree
Showing 59 changed files with 1,230 additions and 75 deletions.
27 changes: 27 additions & 0 deletions .eslintrc.cjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module.exports = {
env: {
node: true,
},
extends: ['@croquiscom/eslint-config/requiring-type-checking'],
ignorePatterns: ['.eslintrc.cjs', 'lib'],
parserOptions: {
project: ['./tsconfig.json'],
},
rules: {
'import/export': 'off',
'@typescript-eslint/no-unsafe-call': 'off',
'@typescript-eslint/no-unsafe-member-access': 'off',
'@typescript-eslint/no-unsafe-assignment': 'off',
'@typescript-eslint/no-unsafe-return': 'off',
'@typescript-eslint/explicit-module-boundary-types': 'off',
'@typescript-eslint/no-floating-promises': 'off',
'@typescript-eslint/restrict-template-expressions': 'off',
},
settings: {
'import/resolver': {
typescript: {
project: __dirname,
},
},
},
};
20 changes: 0 additions & 20 deletions .eslintrc.json

This file was deleted.

File renamed without changes.
6 changes: 3 additions & 3 deletions lib/index.js → lib/cjs/index.js
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.getPreviousKoreanBusinessDayYmdByUtcDate = exports.getNextKoreanBusinessDayYmdByUtcDate = exports.getPreviousKoreanBusinessDayYmd = exports.getNextKoreanBusinessDayYmd = exports.isHoliday = void 0;
var year_holidays_1 = require("./year_holidays");
var index_js_1 = require("./year_holidays/index.js");
function getYmdByDate(date) {
return {
day: date.getDate(),
Expand Down Expand Up @@ -30,7 +30,7 @@ function getBusinessDay(_a) {
continue;
}
var ymd = getYmdByDate(date);
var holiday_of_year = (_b = year_holidays_1.KOREAN_HOLIDAYS[ymd.year]) !== null && _b !== void 0 ? _b : year_holidays_1.HOLIDAYS_FALLBACK;
var holiday_of_year = (_b = index_js_1.KOREAN_HOLIDAYS[ymd.year]) !== null && _b !== void 0 ? _b : index_js_1.HOLIDAYS_FALLBACK;
var holiday_of_month = holiday_of_year[ymd.month];
if (!holiday_of_month) {
throw new Error("month ".concat(ymd.month, " data not exists"));
Expand All @@ -54,7 +54,7 @@ function isHoliday(date) {
date.setUTCHours(date.getUTCHours() + 9);
var day = date.getDay();
var ymd = getYmdByDate(date);
var holiday_of_year = (_a = year_holidays_1.KOREAN_HOLIDAYS[ymd.year]) !== null && _a !== void 0 ? _a : year_holidays_1.HOLIDAYS_FALLBACK;
var holiday_of_year = (_a = index_js_1.KOREAN_HOLIDAYS[ymd.year]) !== null && _a !== void 0 ? _a : index_js_1.HOLIDAYS_FALLBACK;
var holiday_of_month = holiday_of_year[ymd.month];
var result = (holiday_of_month === null || holiday_of_month === void 0 ? void 0 : holiday_of_month[ymd.day]) !== undefined;
return day === 0 || day === 6 || result;
Expand Down
1 change: 1 addition & 0 deletions lib/cjs/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"type":"commonjs"}
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import { IYearHolidays } from './types';
import { IYearHolidays } from './types.js';
export declare const HOLIDAYS_2019: IYearHolidays;
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import { IYearHolidays } from './types';
import { IYearHolidays } from './types.js';
export declare const HOLIDAYS_2020: IYearHolidays;
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import { IYearHolidays } from './types';
import { IYearHolidays } from './types.js';
export declare const HOLIDAYS_2021: IYearHolidays;
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import { IYearHolidays } from './types';
import { IYearHolidays } from './types.js';
export declare const HOLIDAYS_2022: IYearHolidays;
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,2 +1,2 @@
import { IYearHolidays } from './types';
import { IYearHolidays } from './types.js';
export declare const HOLIDAYS_2023: IYearHolidays;
File renamed without changes.
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
import { IYearHolidays } from './types';
import { IYearHolidays } from './types.js';
declare const HOLIDAYS_FALLBACK: IYearHolidays;
export { HOLIDAYS_FALLBACK };
File renamed without changes.
3 changes: 3 additions & 0 deletions lib/cjs/year_holidays/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
import { IYearHolidays } from './types.js';
export declare const KOREAN_HOLIDAYS: Record<number, IYearHolidays | undefined>;
export { HOLIDAYS_FALLBACK } from './fallback.js';
18 changes: 18 additions & 0 deletions lib/cjs/year_holidays/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.HOLIDAYS_FALLBACK = exports.KOREAN_HOLIDAYS = void 0;
var _2019_js_1 = require("./2019.js");
var _2020_js_1 = require("./2020.js");
var _2021_js_1 = require("./2021.js");
var _2022_js_1 = require("./2022.js");
var _2023_js_1 = require("./2023.js");
// 토, 일요일 정보는 포함하지 않음
exports.KOREAN_HOLIDAYS = {
2019: _2019_js_1.HOLIDAYS_2019,
2020: _2020_js_1.HOLIDAYS_2020,
2021: _2021_js_1.HOLIDAYS_2021,
2022: _2022_js_1.HOLIDAYS_2022,
2023: _2023_js_1.HOLIDAYS_2023,
};
var fallback_js_1 = require("./fallback.js");
Object.defineProperty(exports, "HOLIDAYS_FALLBACK", { enumerable: true, get: function () { return fallback_js_1.HOLIDAYS_FALLBACK; } });
File renamed without changes.
File renamed without changes.
34 changes: 34 additions & 0 deletions lib/esm/index.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
/**
* 휴일 여부를 반환합니다.
* @param date 살펴볼 날짜
* @returns 휴일 여부
*/
export declare function isHoliday(date: Date): boolean;
/**
* YYYYMMDD 형태의 숫자를 입력으로 받아 영업일 기준 n일 후를 반환합니다.
* @param day_ymd 기준일(YYYYMMDD 형태의 숫자)
* @param days_after n일 후
* @returns 다음 영업일(YYYYMMDD 형태의 숫자)
*/
export declare function getNextKoreanBusinessDayYmd(day_ymd: number, days_after: number): number;
/**
* YYYYMMDD 형태의 숫자를 입력으로 받아 영업일 기준 n일 전을 반환합니다.
* @param day_ymd 기준일(YYYYMMDD 형태의 숫자)
* @param days_after n일 전
* @returns 이전 영업일(YYYYMMDD 형태의 숫자)
*/
export declare function getPreviousKoreanBusinessDayYmd(day_ymd: number, days_before: number): number;
/**
* UTC 시간대의 Date 인스턴스를 입력으로 받아 영업일 기준 n일 후를 반환합니다.
* @param date 기준일(UTC 시각)
* @param days_after n일 후
* @returns 다음 영업일(YYYYMMDD 형태의 숫자)
*/
export declare function getNextKoreanBusinessDayYmdByUtcDate(date: Date, days_after: number): number;
/**
* UTC 시간대의 Date 인스턴스를 입력으로 받아 영업일 기준 n일 전을 반환합니다.
* @param date 기준일(UTC 시각)
* @param days_after n일 전
* @returns 이전 영업일(YYYYMMDD 형태의 숫자)
*/
export declare function getPreviousKoreanBusinessDayYmdByUtcDate(date: Date, days_before: number): number;
114 changes: 114 additions & 0 deletions lib/esm/index.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,114 @@
import { HOLIDAYS_FALLBACK, KOREAN_HOLIDAYS } from './year_holidays/index.js';
function getYmdByDate(date) {
return {
day: date.getDate(),
month: date.getMonth() + 1,
year: date.getFullYear(),
};
}
function getDateFromDayYmd(day_ymd) {
if (!/^20[0-9][0-9](0[1-9]|1[0-2])(0[1-9]|1[0-9]|2[0-9]|3[0-1])$/.test(String(day_ymd))) {
throw new Error("invalid day_ymd: ".concat(day_ymd));
}
var day_m = "0".concat(Math.floor((day_ymd / 100) % 100)).slice(-2);
var day_d = "0".concat(Math.floor(day_ymd % 100)).slice(-2);
return new Date("".concat(Math.floor(day_ymd / 10000), "-").concat(day_m, "-").concat(day_d, "T09:00:00+09:00"));
}
function getBusinessDay(_a) {
var _b;
var date = _a.date, days_to_go = _a.days_to_go, set_date_increased = _a.set_date_increased;
if (days_to_go < 1) {
throw new Error("second parameter value should be positive value");
}
while (days_to_go) {
date.setDate(date.getDate() + (set_date_increased ? 1 : -1));
var day = date.getDay();
if (day === 0 || day === 6) {
continue;
}
var ymd = getYmdByDate(date);
var holiday_of_year = (_b = KOREAN_HOLIDAYS[ymd.year]) !== null && _b !== void 0 ? _b : HOLIDAYS_FALLBACK;
var holiday_of_month = holiday_of_year[ymd.month];
if (!holiday_of_month) {
throw new Error("month ".concat(ymd.month, " data not exists"));
}
if (holiday_of_month[ymd.day]) {
continue;
}
days_to_go--;
}
var result = getYmdByDate(date);
return result.year * 10000 + result.month * 100 + result.day;
}
/**
* 휴일 여부를 반환합니다.
* @param date 살펴볼 날짜
* @returns 휴일 여부
*/
export function isHoliday(date) {
var _a;
date = new Date(date);
date.setUTCHours(date.getUTCHours() + 9);
var day = date.getDay();
var ymd = getYmdByDate(date);
var holiday_of_year = (_a = KOREAN_HOLIDAYS[ymd.year]) !== null && _a !== void 0 ? _a : HOLIDAYS_FALLBACK;
var holiday_of_month = holiday_of_year[ymd.month];
var result = (holiday_of_month === null || holiday_of_month === void 0 ? void 0 : holiday_of_month[ymd.day]) !== undefined;
return day === 0 || day === 6 || result;
}
/**
* YYYYMMDD 형태의 숫자를 입력으로 받아 영업일 기준 n일 후를 반환합니다.
* @param day_ymd 기준일(YYYYMMDD 형태의 숫자)
* @param days_after n일 후
* @returns 다음 영업일(YYYYMMDD 형태의 숫자)
*/
export function getNextKoreanBusinessDayYmd(day_ymd, days_after) {
return getBusinessDay({
date: getDateFromDayYmd(day_ymd),
days_to_go: days_after,
set_date_increased: true,
});
}
/**
* YYYYMMDD 형태의 숫자를 입력으로 받아 영업일 기준 n일 전을 반환합니다.
* @param day_ymd 기준일(YYYYMMDD 형태의 숫자)
* @param days_after n일 전
* @returns 이전 영업일(YYYYMMDD 형태의 숫자)
*/
export function getPreviousKoreanBusinessDayYmd(day_ymd, days_before) {
return getBusinessDay({
date: getDateFromDayYmd(day_ymd),
days_to_go: days_before,
set_date_increased: false,
});
}
/**
* UTC 시간대의 Date 인스턴스를 입력으로 받아 영업일 기준 n일 후를 반환합니다.
* @param date 기준일(UTC 시각)
* @param days_after n일 후
* @returns 다음 영업일(YYYYMMDD 형태의 숫자)
*/
export function getNextKoreanBusinessDayYmdByUtcDate(date, days_after) {
date = new Date(date);
date.setUTCHours(date.getUTCHours() + 9);
return getBusinessDay({
date: date,
days_to_go: days_after,
set_date_increased: true,
});
}
/**
* UTC 시간대의 Date 인스턴스를 입력으로 받아 영업일 기준 n일 전을 반환합니다.
* @param date 기준일(UTC 시각)
* @param days_after n일 전
* @returns 이전 영업일(YYYYMMDD 형태의 숫자)
*/
export function getPreviousKoreanBusinessDayYmdByUtcDate(date, days_before) {
date = new Date(date);
date.setUTCHours(date.getUTCHours() + 9);
return getBusinessDay({
date: date,
days_to_go: days_before,
set_date_increased: false,
});
}
2 changes: 2 additions & 0 deletions lib/esm/year_holidays/2019.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { IYearHolidays } from './types.js';
export declare const HOLIDAYS_2019: IYearHolidays;
39 changes: 39 additions & 0 deletions lib/esm/year_holidays/2019.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,39 @@
export var HOLIDAYS_2019 = {
1: {
1: true, // 신정
},
2: {
4: true,
5: true,
6: true, // 설날 연휴
},
3: {
1: true, // 삼일절
},
4: {},
5: {
5: true,
6: true,
12: true, // 부처님 오신날
},
6: {
6: true, // 현충일
},
7: {},
8: {
15: true, // 광복절
},
9: {
12: true,
13: true,
14: true, // 추석 연휴
},
10: {
3: true,
9: true, // 한글날
},
11: {},
12: {
25: true, // 크리스마스
},
};
2 changes: 2 additions & 0 deletions lib/esm/year_holidays/2020.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { IYearHolidays } from './types.js';
export declare const HOLIDAYS_2020: IYearHolidays;
42 changes: 42 additions & 0 deletions lib/esm/year_holidays/2020.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
export var HOLIDAYS_2020 = {
1: {
1: true,
24: true,
25: true,
26: true,
27: true, // 대체 휴일
},
2: {},
3: {
1: true, // 삼일절
},
4: {
15: true,
30: true, // 부처님 오신날
},
5: {
1: true,
5: true, // 어린이날
},
6: {
6: true, // 현충일
},
7: {},
8: {
15: true,
17: true, // 광복절 대체 임시공휴일
},
9: {
30: true, // 추석 연휴
},
10: {
1: true,
2: true,
3: true,
9: true, // 한글날
},
11: {},
12: {
25: true, // 성탄절
},
};
2 changes: 2 additions & 0 deletions lib/esm/year_holidays/2021.d.ts
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
import { IYearHolidays } from './types.js';
export declare const HOLIDAYS_2021: IYearHolidays;
Loading

0 comments on commit 2e5268d

Please sign in to comment.