holidays-jp 1.4.0 → 2.0.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 CHANGED
@@ -1,10 +1,8 @@
1
1
  # holidays-jp.js
2
2
 
3
3
  [![test](https://github.com/sasaplus1/holidays-jp.js/workflows/test/badge.svg)](https://github.com/sasaplus1/holidays-jp.js/actions?query=workflow%3Atest)
4
- [![update](https://github.com/sasaplus1/holidays-jp.js/workflows/update/badge.svg)](https://github.com/sasaplus1/holidays-jp.js/actions?query=workflow%3Aupdate)
5
4
  [![npm version](https://badge.fury.io/js/holidays-jp.svg)](https://badge.fury.io/js/holidays-jp)
6
5
  [![Try holidays-jp on RunKit](https://badge.runkitcdn.com/holidays-jp.svg)](https://npm.runkit.com/holidays-jp)
7
- [![renovate](https://badges.renovateapi.com/github/sasaplus1/holidays-jp.js)](https://renovatebot.com)
8
6
 
9
7
  get Japanese public holidays
10
8
 
@@ -42,10 +40,6 @@ const date = new Date(2019, 1 - 1, 1, 0, 0, 0, 0);
42
40
  holidays.getHolidayInfo(date); // => { date: '2019-01-01', name: '元日', ... }
43
41
  ```
44
42
 
45
- ## Functions
46
-
47
- see [documents](https://sasaplus1.github.io/holidays-jp.js)
48
-
49
43
  ### CLI
50
44
 
51
45
  holidays-jp.js has CLI command:
@@ -72,32 +66,9 @@ $ echo $?
72
66
  1
73
67
  ```
74
68
 
75
- ## holidays data
76
-
77
- holidays-jp.js has some format holidays data, it converted from [syukujitsu.csv](https://www8.cao.go.jp/chosei/shukujitsu/syukujitsu.csv):
78
-
79
- ```js
80
- const fs = require('fs');
81
-
82
- const js = require('holidays-jp/data.js');
83
- const json = require('holidays-jp/data.json');
84
-
85
- const csv = fs.readFileSync(require.resolve('holidays-jp/data.csv'), 'utf8');
86
- const tsv = fs.readFileSync(require.resolve('holidays-jp/data.tsv'), 'utf8');
87
- const ltsv = fs.readFileSync(require.resolve('holidays-jp/data.ltsv'), 'utf8');
88
- ```
89
-
90
- ```js
91
- import data from 'holidays-jp/data.mjs';
92
- ```
93
-
94
- ```ts
95
- import data from 'holidays-jp/data.ts';
96
- ```
97
-
98
69
  ### Related
99
70
 
100
- [「国民の祝日」について](https://www8.cao.go.jp/chosei/shukujitsu/gaiyou.html)
71
+ - [sasaplus1/japanese-public-holidays](https://github.com/sasaplus1/japanese-public-holidays)
101
72
 
102
73
  ## License
103
74
 
@@ -0,0 +1,34 @@
1
+ export type HolidayInfo = {
2
+ date: string;
3
+ endDate: Date;
4
+ name: string;
5
+ startDate: Date;
6
+ };
7
+ export type HolidayMap = {
8
+ [key: string]: {
9
+ [key: string]: {
10
+ [key: string]: HolidayInfo;
11
+ };
12
+ };
13
+ };
14
+ export declare const holidays: {
15
+ date: string;
16
+ endDate: Date;
17
+ name: string;
18
+ startDate: Date;
19
+ }[];
20
+ export declare const holidayMap: HolidayMap;
21
+ /**
22
+ * get holiday info
23
+ *
24
+ * @param date - target date
25
+ * @returns return holiday info if date is holiday, otherwise return null
26
+ */
27
+ export declare function getHolidayInfo(date: Date): HolidayInfo | null;
28
+ /**
29
+ * return true if date is holiday
30
+ *
31
+ * @param date - target date
32
+ * @returns return true if date is holiday
33
+ */
34
+ export declare function isHoliday(date: Date): boolean;
@@ -0,0 +1,97 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", { value: true });
3
+ exports.isHoliday = exports.getHolidayInfo = exports.holidayMap = exports.holidays = void 0;
4
+ const japanese_public_holidays_1 = require("japanese-public-holidays");
5
+ // NOTE: JST is UTC+9:00
6
+ const jstOffsetHour = 1000 * 60 * 60 * 9;
7
+ // NOTE: find backward is faster than find forward maybe
8
+ exports.holidays = japanese_public_holidays_1.holidays.reverse().map(function (holiday) {
9
+ const { date, name } = holiday;
10
+ const [year, month, day] = date.split('-').map(Number);
11
+ if (year === undefined || month === undefined || day === undefined) {
12
+ return {
13
+ date,
14
+ endDate: new Date(''),
15
+ name,
16
+ startDate: new Date('')
17
+ };
18
+ }
19
+ const startDate = new Date(Date.UTC(year, month - 1, day, 0, 0, 0, 0) - jstOffsetHour);
20
+ const endDate = new Date(Date.UTC(year, month - 1, day + 1, 0, 0, 0, 0) - jstOffsetHour - 1);
21
+ return {
22
+ date,
23
+ endDate,
24
+ name,
25
+ startDate
26
+ };
27
+ });
28
+ exports.holidayMap = exports.holidays.reduce(function (result, holiday) {
29
+ const { date } = holiday;
30
+ const [year, month, day] = date.split('-');
31
+ if (year === undefined || month === undefined || day === undefined) {
32
+ return result;
33
+ }
34
+ const yearObject = ensureKey(result, year);
35
+ const monthObject = ensureKey(yearObject, month);
36
+ monthObject[day] = holiday;
37
+ return result;
38
+ }, {});
39
+ /**
40
+ * get holiday info
41
+ *
42
+ * @param date - target date
43
+ * @returns return holiday info if date is holiday, otherwise return null
44
+ */
45
+ function getHolidayInfo(date) {
46
+ if (!isDate(date)) {
47
+ throw new TypeError('date must be a Date: ' + date);
48
+ }
49
+ const jstDate = new Date(date.getTime() + jstOffsetHour);
50
+ const m = jstDate.getUTCMonth() + 1;
51
+ const d = jstDate.getUTCDate();
52
+ const year = String(jstDate.getUTCFullYear());
53
+ const month = m < 10 ? `0${m}` : String(m);
54
+ const day = d < 10 ? `0${d}` : String(d);
55
+ const yearObject = ensureKey(exports.holidayMap, year);
56
+ const monthObject = ensureKey(yearObject, month);
57
+ const result = monthObject[day];
58
+ return result === undefined ? null : result;
59
+ }
60
+ exports.getHolidayInfo = getHolidayInfo;
61
+ /**
62
+ * return true if date is holiday
63
+ *
64
+ * @param date - target date
65
+ * @returns return true if date is holiday
66
+ */
67
+ function isHoliday(date) {
68
+ if (!isDate(date)) {
69
+ throw new TypeError('date must be a Date: ' + date);
70
+ }
71
+ return getHolidayInfo(date) !== null;
72
+ }
73
+ exports.isHoliday = isHoliday;
74
+ /** cache of Object.prototype.toString */
75
+ const toString = Object.prototype.toString;
76
+ /**
77
+ * return true if date is Date instance
78
+ *
79
+ * @param value - target value
80
+ * @returns return true if value is date
81
+ */
82
+ function isDate(value) {
83
+ return toString.call(value) === '[object Date]';
84
+ }
85
+ /**
86
+ * for TS2532
87
+ *
88
+ * @param object - target object
89
+ * @returns object
90
+ */
91
+ function ensureKey(object, key) {
92
+ if (!object[key]) {
93
+ object[key] = {};
94
+ }
95
+ return object[key];
96
+ }
97
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":";;;AAAA,uEAAoE;AAiBpE,wBAAwB;AACxB,MAAM,aAAa,GAAG,IAAI,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AAEzC,wDAAwD;AAC3C,QAAA,QAAQ,GAAG,mCAAY,CAAC,OAAO,EAAE,CAAC,GAAG,CAAC,UAAU,OAAO;IAClE,MAAM,EAAE,IAAI,EAAE,IAAI,EAAE,GAAG,OAAO,CAAC;IAE/B,MAAM,CAAC,IAAI,EAAE,KAAK,EAAE,GAAG,CAAC,GAAG,IAAI,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC,GAAG,CAAC,MAAM,CAAC,CAAC;IAEvD,IAAI,IAAI,KAAK,SAAS,IAAI,KAAK,KAAK,SAAS,IAAI,GAAG,KAAK,SAAS,EAAE;QAClE,OAAO;YACL,IAAI;YACJ,OAAO,EAAE,IAAI,IAAI,CAAC,EAAE,CAAC;YACrB,IAAI;YACJ,SAAS,EAAE,IAAI,IAAI,CAAC,EAAE,CAAC;SACxB,CAAC;KACH;IAED,MAAM,SAAS,GAAG,IAAI,IAAI,CACxB,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,GAAG,CAAC,EAAE,GAAG,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,EAAE,CAAC,CAAC,GAAG,aAAa,CAC3D,CAAC;IACF,MAAM,OAAO,GAAG,IAAI,IAAI,CACtB,IAAI,CAAC,GAAG,CAAC,IAAI,EAAE,KAAK,GAAG,CAAC,EAAE,GAAG,GAAG,CAAC,EAAE,CAAC,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: string;
3
+ endDate: Date;
4
+ name: string;
5
+ startDate: Date;
6
+ };
7
+ export type HolidayMap = {
8
+ [key: string]: {
9
+ [key: string]: {
10
+ [key: string]: HolidayInfo;
11
+ };
12
+ };
13
+ };
14
+ export declare const holidays: {
15
+ date: string;
16
+ endDate: Date;
17
+ name: string;
18
+ startDate: Date;
19
+ }[];
20
+ export declare const holidayMap: HolidayMap;
21
+ /**
22
+ * get holiday info
23
+ *
24
+ * @param date - target date
25
+ * @returns return holiday info if date is holiday, otherwise return null
26
+ */
27
+ export declare function getHolidayInfo(date: Date): HolidayInfo | null;
28
+ /**
29
+ * return true if date is holiday
30
+ *
31
+ * @param date - target date
32
+ * @returns return true if date is holiday
33
+ */
34
+ export declare function isHoliday(date: Date): boolean;
@@ -0,0 +1,92 @@
1
+ import { holidays as baseHolidays } from 'japanese-public-holidays';
2
+ // NOTE: JST is UTC+9:00
3
+ const jstOffsetHour = 1000 * 60 * 60 * 9;
4
+ // NOTE: find backward is faster than find forward maybe
5
+ export const holidays = baseHolidays.reverse().map(function (holiday) {
6
+ const { date, name } = holiday;
7
+ const [year, month, day] = date.split('-').map(Number);
8
+ if (year === undefined || month === undefined || day === undefined) {
9
+ return {
10
+ date,
11
+ endDate: new Date(''),
12
+ name,
13
+ startDate: new Date('')
14
+ };
15
+ }
16
+ const startDate = new Date(Date.UTC(year, month - 1, day, 0, 0, 0, 0) - jstOffsetHour);
17
+ const endDate = new Date(Date.UTC(year, month - 1, day + 1, 0, 0, 0, 0) - jstOffsetHour - 1);
18
+ return {
19
+ date,
20
+ endDate,
21
+ name,
22
+ startDate
23
+ };
24
+ });
25
+ export const holidayMap = holidays.reduce(function (result, holiday) {
26
+ const { date } = holiday;
27
+ const [year, month, day] = date.split('-');
28
+ if (year === undefined || month === undefined || day === undefined) {
29
+ return result;
30
+ }
31
+ const yearObject = ensureKey(result, year);
32
+ const monthObject = ensureKey(yearObject, month);
33
+ monthObject[day] = holiday;
34
+ return result;
35
+ }, {});
36
+ /**
37
+ * get holiday info
38
+ *
39
+ * @param date - target date
40
+ * @returns return holiday info if date is holiday, otherwise return null
41
+ */
42
+ export function getHolidayInfo(date) {
43
+ if (!isDate(date)) {
44
+ throw new TypeError('date must be a Date: ' + date);
45
+ }
46
+ const jstDate = new Date(date.getTime() + jstOffsetHour);
47
+ const m = jstDate.getUTCMonth() + 1;
48
+ const d = jstDate.getUTCDate();
49
+ const year = String(jstDate.getUTCFullYear());
50
+ const month = m < 10 ? `0${m}` : String(m);
51
+ const day = d < 10 ? `0${d}` : String(d);
52
+ const yearObject = ensureKey(holidayMap, year);
53
+ const monthObject = ensureKey(yearObject, month);
54
+ const result = monthObject[day];
55
+ return result === undefined ? null : result;
56
+ }
57
+ /**
58
+ * return true if date is holiday
59
+ *
60
+ * @param date - target date
61
+ * @returns return true if date is holiday
62
+ */
63
+ export function isHoliday(date) {
64
+ if (!isDate(date)) {
65
+ throw new TypeError('date must be a Date: ' + date);
66
+ }
67
+ return getHolidayInfo(date) !== null;
68
+ }
69
+ /** cache of Object.prototype.toString */
70
+ const toString = Object.prototype.toString;
71
+ /**
72
+ * return true if date is Date instance
73
+ *
74
+ * @param value - target value
75
+ * @returns return true if value is date
76
+ */
77
+ function isDate(value) {
78
+ return toString.call(value) === '[object Date]';
79
+ }
80
+ /**
81
+ * for TS2532
82
+ *
83
+ * @param object - target object
84
+ * @returns object
85
+ */
86
+ function ensureKey(object, key) {
87
+ if (!object[key]) {
88
+ object[key] = {};
89
+ }
90
+ return object[key];
91
+ }
92
+ //# sourceMappingURL=index.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"index.js","sourceRoot":"","sources":["../../index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,QAAQ,IAAI,YAAY,EAAE,MAAM,0BAA0B,CAAC;AAiBpE,wBAAwB;AACxB,MAAM,aAAa,GAAG,IAAI,GAAG,EAAE,GAAG,EAAE,GAAG,CAAC,CAAC;AAEzC,wDAAwD;AACxD,MAAM,CAAC,MAAM,Q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AC,CAAC;IAEhC,OAAO,MAAM,KAAK,SAAS,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,MAAM,CAAC;AAC9C,CAAC;AAED;;;;;GAKG;AACH,MAAM,UAAU,SAAS,CAAC,IAAU;IAClC,IAAI,CAAC,MAAM,CAAC,IAAI,CAAC,EAAE;QACjB,MAAM,IAAI,SAAS,CAAC,uBAAuB,GAAG,IAAI,CAAC,CAAC;KACrD;IAED,OAAO,cAAc,CAAC,IAAI,CAAC,KAAK,IAAI,CAAC;AACvC,CAAC;AAED,yCAAyC;AACzC,MAAM,QAAQ,GAAG,MAAM,CAAC,SAAS,CAAC,QAAQ,CAAC;AAE3C;;;;;GAKG;AACH,SAAS,MAAM,CAAC,KAAc;IAC5B,OAAO,QAAQ,CAAC,IAAI,CAAC,KAAK,CAAC,KAAK,eAAe,CAAC;AAClD,CAAC;AAED;;;;;GAKG;AACH,SAAS,SAAS,CAAI,MAAqC,EAAE,GAAW;IACtE,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,EAAE;QAChB,MAAM,CAAC,GAAG,CAAC,GAAG,EAAO,CAAC;KACvB;IAED,OAAO,MAAM,CAAC,GAAG,CAAE,CAAC;AACtB,CAAC"}
@@ -0,0 +1,36 @@
1
+ declare module "index" {
2
+ export type HolidayInfo = {
3
+ date: string;
4
+ endDate: Date;
5
+ name: string;
6
+ startDate: Date;
7
+ };
8
+ export type HolidayMap = {
9
+ [key: string]: {
10
+ [key: string]: {
11
+ [key: string]: HolidayInfo;
12
+ };
13
+ };
14
+ };
15
+ export const holidays: {
16
+ date: string;
17
+ endDate: Date;
18
+ name: string;
19
+ startDate: Date;
20
+ }[];
21
+ export const holidayMap: HolidayMap;
22
+ /**
23
+ * get holiday info
24
+ *
25
+ * @param date - target date
26
+ * @returns return holiday info if date is holiday, otherwise return null
27
+ */
28
+ export function getHolidayInfo(date: Date): HolidayInfo | null;
29
+ /**
30
+ * return true if date is holiday
31
+ *
32
+ * @param date - target date
33
+ * @returns return true if date is holiday
34
+ */
35
+ export function isHoliday(date: Date): boolean;
36
+ }
package/package.json CHANGED
@@ -1,56 +1,57 @@
1
1
  {
2
2
  "name": "holidays-jp",
3
3
  "description": "get Japanese public holidays",
4
- "version": "1.4.0",
4
+ "version": "2.0.1",
5
5
  "author": "sasa+1 <sasaplus1@gmail.com>",
6
6
  "bin": {
7
7
  "holiday": "bin/holidays-jp.js",
8
8
  "holidays-jp": "bin/holidays-jp.js"
9
9
  },
10
- "browser": "dist/holidays-jp.js",
10
+ "dependencies": {
11
+ "japanese-public-holidays": "^3.0.6"
12
+ },
11
13
  "devDependencies": {
12
- "@types/mocha": "^8.0.0",
13
- "@types/node": "^12.7.2",
14
- "@typescript-eslint/eslint-plugin": "^4.0.0",
15
- "@typescript-eslint/parser": "^4.0.0",
16
- "csv-parse": "^4.4.5",
17
- "csv-stringify": "^5.3.3",
18
- "download": "^8.0.0",
19
- "eslint": "^7.0.0",
20
- "eslint-config-prettier": "^7.0.0",
14
+ "@tsconfig/strictest": "^2.0.1",
15
+ "@types/node": "^18.0.0",
16
+ "@typescript-eslint/eslint-plugin": "^6.0.0",
17
+ "@typescript-eslint/parser": "^6.0.0",
18
+ "eslint": "^8.0.0",
19
+ "eslint-config-prettier": "^8.0.0",
21
20
  "eslint-plugin-node": "^11.0.0",
22
- "espower-typescript": "^9.0.2",
23
- "husky": "^4.0.0",
24
- "iconv-lite": "^0.6.0",
25
- "karma": "^5.0.0",
26
- "karma-chrome-launcher": "^3.1.0",
27
- "karma-mocha": "^2.0.0",
28
- "karma-rollup-preprocessor": "^7.0.2",
29
- "lint-staged": "^10.0.0",
30
- "ltsv": "^2.0.0",
31
- "mocha": "^8.0.0",
21
+ "eslint-plugin-tsdoc": "^0.2.17",
32
22
  "npm-run-all": "^4.1.5",
33
- "power-assert": "^1.6.1",
34
- "prettier": "^2.2.1",
35
- "rimraf": "^3.0.0",
36
- "rollup": "^2.0.0",
37
- "rollup-plugin-terser": "^7.0.0",
38
- "rollup-plugin-typescript": "^1.0.1",
39
- "through2": "^4.0.0",
40
- "typedoc": "^0.20.0",
41
- "typescript": "^4.0.0"
23
+ "prettier": "^3.0.0",
24
+ "typescript": "^5.0.0"
25
+ },
26
+ "engines": {
27
+ "node": ">=8.3"
28
+ },
29
+ "exports": {
30
+ ".": {
31
+ "import": "./dist/esm/index.js",
32
+ "require": "./dist/cjs/index.js",
33
+ "types": "./dist/index.d.ts"
34
+ }
42
35
  },
43
36
  "files": [
44
37
  "bin/holidays-jp.js",
45
- "data.*",
46
- "index.d.ts",
47
- "index.js",
48
- "index.js.map",
49
- "index.mjs"
38
+ "dist/*"
50
39
  ],
51
40
  "license": "MIT",
52
- "main": "index.js",
53
- "module": "index.mjs",
41
+ "main": "./dist/cjs/index.js",
42
+ "module": "./dist/esm/index.js",
43
+ "prettier": {
44
+ "singleQuote": true,
45
+ "trailingComma": "none",
46
+ "overrides": [
47
+ {
48
+ "files": "*.json",
49
+ "options": {
50
+ "parser": "json-stringify"
51
+ }
52
+ }
53
+ ]
54
+ },
54
55
  "readmeFilename": "README.md",
55
56
  "repository": {
56
57
  "type": "git",
@@ -58,34 +59,22 @@
58
59
  },
59
60
  "scripts": {
60
61
  "build": "run-p -l build:*",
61
- "build-documents": "typedoc",
62
- "build:cjs": "tsc",
63
- "build:esm": "rollup -c --environment data:esm",
64
- "build:umd": "rollup -c --environment data:umd",
65
- "check-types": "tsc --noEmit",
66
- "download": "node ./npm_script/download.js",
62
+ "build:cjs": "tsc -p .tsconfigs/cjs.json",
63
+ "build:dts": "tsc -p .tsconfigs/dts.json",
64
+ "build:esm": "tsc -p .tsconfigs/esm.json",
67
65
  "fix": "run-s fix:*",
68
- "fix:eslint": "eslint --cache --fix --ext .js,.ts .",
69
- "fix:prettier": "prettier --write '**/*.(js|ts)'",
70
- "fixpack": "npx fixpack",
71
- "generate": "run-p -l generate:*",
72
- "generate:csv": "node ./npm_script/csv_to_csv.js < ./syukujitsu.csv > ./data.csv",
73
- "generate:json": "node ./npm_script/csv_to_json.js < ./syukujitsu.csv > ./data.json",
74
- "generate:ltsv": "node ./npm_script/csv_to_ltsv.js < ./syukujitsu.csv > ./data.ltsv",
75
- "generate:ts": "node ./npm_script/csv_to_ts.js < ./syukujitsu.csv > ./data.ts",
76
- "generate:tsv": "node ./npm_script/csv_to_tsv.js < ./syukujitsu.csv > ./data.tsv",
66
+ "fix:eslint": "eslint --fix .",
67
+ "fix:fixpack": "npx fixpack",
68
+ "fix:prettier": "prettier --write .",
77
69
  "lint": "run-s lint:*",
78
- "lint:eslint": "eslint --cache --ext .js,.ts .",
79
- "lint:prettier": "prettier --check '**/*.(js|ts)'",
80
- "postbuild:esm": "prettier --parser babel --write ./index.mjs ./data.mjs",
81
- "postgenerate": "rimraf ./syukujitsu.csv",
82
- "postgenerate:ts": "prettier --parser typescript --write ./data.ts",
83
- "pregenerate": "run-s -s download > ./syukujitsu.csv",
84
- "pretest": "run-s build:cjs",
85
- "pretest:browser": "run-s build:umd",
86
- "test": "mocha",
87
- "test:browser": "karma start --single-run"
70
+ "lint:eslint": "eslint .",
71
+ "lint:fixpack": "npx fixpack --dryRun",
72
+ "lint:prettier": "prettier --check .",
73
+ "lint:tsc": "tsc -p .tsconfigs/lint.json",
74
+ "posttest": "rm -f index.test.js",
75
+ "pretest": "tsc -p .tsconfigs/cjs.json && tsc -p .tsconfigs/test.json",
76
+ "test": "node --test"
88
77
  },
89
78
  "sideEffects": false,
90
- "types": "index.d.ts"
79
+ "types": "./dist/index.d.ts"
91
80
  }
package/HISTORY.md DELETED
@@ -1,29 +0,0 @@
1
- # 1.4.0 / 2021-02-07
2
-
3
- - update holidays data
4
-
5
- # 1.3.0 / 2020-12-01
6
-
7
- - update holidays data
8
-
9
- # 1.2.2 / 2020-03-04
10
-
11
- - update holidays data
12
-
13
- # 1.2.1 / 2019-09-18
14
-
15
- - update holidays data
16
-
17
- # 1.2.0 / 2019-08-22
18
-
19
- - rewrite codebase to TypeScript
20
- - add ES Module format and UMD format scripts
21
- - improve metadata for script bundler
22
-
23
- # 1.1.0 / 2019-08-19
24
-
25
- - add CLI command
26
-
27
- # 1.0.0 / 2019-08-18
28
-
29
- - initial release