date-holidays 3.40.1 → 4.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/lib/Holidays.cjs CHANGED
@@ -1,6 +1,7 @@
1
1
  'use strict';
2
2
 
3
3
  var HolidaysParser = require('date-holidays-parser');
4
+ var plugins = require('date-holidays-parser/plugins');
4
5
  var data = require('./data.cjs');
5
6
 
6
7
  function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
@@ -14,15 +15,16 @@ var HolidaysParser__default = /*#__PURE__*/_interopDefault(HolidaysParser);
14
15
 
15
16
 
16
17
  /** @typedef {import('date-holidays-parser').Location} Location */
17
- /** @typedef {import('date-holidays-parser').HolidayOptions} HolidayOptions */
18
+ /** @typedef {import('caldate').TimezoneAdapter} TimezoneAdapter */
19
+ /** @typedef {import('date-holidays-parser').HolidaysOptions} HolidaysOptions */
18
20
 
19
21
  /**
20
22
  * @class
21
23
  * @param {object} data - holiday data object - see data/holidays.json
22
- * @param {string|Location} [country] - country code or location object
23
- * @param {string} [state] - specifies state
24
- * @param {string} [region] - specifies region
25
- * @param {HolidayOptions} [opts] - options
24
+ * @param {string|Location|HolidaysOptions} [country] - country code, location object, or options
25
+ * @param {string|HolidaysOptions} [state] - state or options
26
+ * @param {string|HolidaysOptions} [region] - region or options
27
+ * @param {HolidaysOptions} [opts] - options
26
28
  * @example
27
29
  * ```js
28
30
  * new Holiday('US', 'la', 'no') // is the same as
@@ -30,10 +32,41 @@ var HolidaysParser__default = /*#__PURE__*/_interopDefault(HolidaysParser);
30
32
  * new Holiday({ country: 'us', state: 'la', region: 'no'})
31
33
  * ```
32
34
  */
33
- class Holidays extends HolidaysParser__default.default {
35
+ class HolidaysBase extends HolidaysParser__default.default {
36
+ /** @type {TimezoneAdapter|undefined} */
37
+ static defaultTimezoneAdapter
38
+
39
+ /**
40
+ * @param {string|Location|HolidaysOptions} [country]
41
+ * @param {string|HolidaysOptions} [state]
42
+ * @param {string|HolidaysOptions} [region]
43
+ * @param {HolidaysOptions} [opts]
44
+ */
34
45
  constructor (country, state, region, opts) {
46
+ if (region && typeof region === 'object') {
47
+ opts = region;
48
+ region = undefined;
49
+ } else if (state && typeof state === 'object') {
50
+ opts = state;
51
+ state = undefined;
52
+ } else if (
53
+ country &&
54
+ typeof country === 'object' &&
55
+ !('country' in country)
56
+ ) {
57
+ opts = country;
58
+ country = undefined;
59
+ }
60
+
61
+ opts = opts || {};
62
+ opts = {
63
+ ...opts,
64
+ plugins: opts.plugins === undefined ? plugins.plugins : opts.plugins,
65
+ timezoneAdapter:
66
+ opts.timezoneAdapter ?? /** @type {typeof HolidaysBase} */ (new.target).defaultTimezoneAdapter
67
+ };
35
68
  super(data.data, country, state, region, opts);
36
69
  }
37
70
  }
38
71
 
39
- exports.Holidays = Holidays;
72
+ exports.HolidaysBase = HolidaysBase;
package/lib/index.cjs CHANGED
@@ -1,7 +1,20 @@
1
1
  'use strict';
2
2
 
3
- var Holidays = require('./Holidays.cjs');
3
+ var momentTimezone = require('caldate/moment-timezone');
4
+ var Holidays$1 = require('./Holidays.cjs');
4
5
 
6
+ /** @typedef {import('date-holidays-parser').Location} Location */
7
+ /** @typedef {import('date-holidays-parser').ActiveRange} ActiveRange */
8
+ /** @typedef {import('date-holidays-parser').HolidayOptions} HolidayOptions */
9
+ /** @typedef {import('date-holidays-parser').HolidayRuleOptions} HolidayRuleOptions */
10
+ /** @typedef {import('date-holidays-parser').Holiday} Holiday */
11
+ /** @typedef {import('date-holidays-parser').HolidayMap} HolidayMap */
12
+ /** @typedef {import('date-holidays-parser').HolidayType} HolidayType */
5
13
 
6
14
 
7
- module.exports = Holidays.Holidays;
15
+ class Holidays extends Holidays$1.HolidaysBase {
16
+ /** @type {import('caldate').TimezoneAdapter} */
17
+ static defaultTimezoneAdapter = momentTimezone.momentTimezoneAdapter
18
+ }
19
+
20
+ module.exports = Holidays;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "date-holidays",
3
- "version": "3.40.1",
3
+ "version": "4.0.1",
4
4
  "description": "worldwide holidays",
5
5
  "keywords": [
6
6
  "holidays",
@@ -25,10 +25,12 @@
25
25
  "abhijeet117 <abhijeetkumarsah92@gmail.com>",
26
26
  "Adam Otradovec <adam.otradovec@seznam.cz>",
27
27
  "Adminy <adminy@users.noreply.github.com>",
28
+ "adminy <marinbivol10@gmail.com>",
28
29
  "Agus Condro <guzzchangx2@gmail.com>",
29
30
  "Alain Vagner <alain@sous-anneau.org>",
30
31
  "Alex Fernández <alexfernandeznpm@gmail.com>",
31
32
  "Alexandru Pislariu <57287326+AlexandruPislariu@users.noreply.github.com>",
33
+ "AlexandruPislariu <alexandru.pislariu@multiversx.com>",
32
34
  "AlinaA <alinaa874@gmail.com>",
33
35
  "Aljosha Vieth <mail@aljoshavieth.de>",
34
36
  "amalgame21 <93383215+amalgame21@users.noreply.github.com>",
@@ -37,6 +39,7 @@
37
39
  "Artur Kraft <arkraft@users.noreply.github.com>",
38
40
  "ash <makingahabit@gmail.com>",
39
41
  "Asım Mirza Çiftler <asimmirzac@gmail.com>",
42
+ "Mradul Singh <msingh@dealmeridian.com>",
40
43
  "ben <99397608+benkhong@users.noreply.github.com>",
41
44
  "Ben Arwin <github@arwin.net>",
42
45
  "Bilal Gültekin <bilal@Bilals-MacBook-Pro.local>",
@@ -49,6 +52,7 @@
49
52
  "charlie <charliedplett@gmail.com>",
50
53
  "Christian Schinnerl <Schinnerl.Christian@gmail.com>",
51
54
  "Christopher McAvaney <christopher.mcavaney@gmail.com>",
55
+ "CHX606 <1461530475@qq.com>",
52
56
  "Cookie <yoshi.hmd@gmail.com>",
53
57
  "Cristian Andrade <cr.andrade.m@gmail.com>",
54
58
  "Cristóbal Berríos <crisberrios@uc.cl>",
@@ -56,6 +60,7 @@
56
60
  "damon02 <damon@teqplay.nl>",
57
61
  "David Hedlund <davidhedlund@users.noreply.github.com>",
58
62
  "David Álvarez Navarro <david16an@gmail.com>",
63
+ "dbdefault <246079841+dbdefault@users.noreply.github.com>",
59
64
  "Diego Henrique Oliveira <contato@diegoholiveira.com>",
60
65
  "Dominik Bruhn <dominik@menlo79.com>",
61
66
  "DrunkenCloud <drunkencloud99@gmail.com>",
@@ -67,6 +72,7 @@
67
72
  "fasteg <eg.lee@fastfive.co.kr>",
68
73
  "Filip Staffa <fstaffa@cimpress.com>",
69
74
  "Florian SALEUR <dev.daedalus@gmail.com>",
75
+ "Florian SALEUR <dev.daedalus@gmail.com>",
70
76
  "Francesco Ansanelli <f.ansanelli@solution-g.com>",
71
77
  "g1mn <16727837+g1mn@users.noreply.github.com>",
72
78
  "Gabor Borus <gabor.borus@gmail.com>",
@@ -106,6 +112,8 @@
106
112
  "jordanfodera <jordan@humaans.io>",
107
113
  "Jørgen Kalsnes Hagen <43886029+Snailedlt@users.noreply.github.com>",
108
114
  "Josh Luongo <josh@yumait.com.au>",
115
+ "Josh Luongo <joshluongo@me.com>",
116
+ "Joshua Rippon <j.rippon@rocketlab.co.nz>",
109
117
  "Joshua Rippon <joshuarippon1@gmail.com>",
110
118
  "Jukka Lehtimäki <jukka.lehtimaki@atoz.fi>",
111
119
  "Julian Krenge <julian@parcellab.com>",
@@ -113,6 +121,7 @@
113
121
  "Karl Horky <karl.horky@gmail.com>",
114
122
  "Kerstens Maxim <maxim.kerstens@gmail.com>",
115
123
  "Kevin Ley <3976145+kevinley@users.noreply.github.com>",
124
+ "Kevin Ley <kevin@salonkee.lu>",
116
125
  "Kevin Ley <ley.kevin@icloud.com>",
117
126
  "Kevin Samoei <samoeikev@gmail.com>",
118
127
  "Kiernan McColl <kiernan@kzn.io>",
@@ -123,6 +132,7 @@
123
132
  "Leonidas Villeneuve <leonidas@leonidasv.com>",
124
133
  "Liu Hangjiang <lhj1118pzh@live.cn>",
125
134
  "loicngrlwf <private@loicnogier.fr>",
135
+ "Long Nguyen <olragon@gmail.com>",
126
136
  "Long Nguyen <olragon@users.noreply.github.com>",
127
137
  "Lorenzo Breda <lorenzo.breda@net.va>",
128
138
  "Lukas Eipert <git@leipert.io>",
@@ -134,6 +144,7 @@
134
144
  "Maty <35110087+M4TY@users.noreply.github.com>",
135
145
  "Matyáš Himmer <matyhimmer@gmail.com>",
136
146
  "Mauro Braggio <m.braggio@e-time.it>",
147
+ "mehlhorn <mail@nils-mehlhorn.de>",
137
148
  "mirobimbo <mirobimbo@gmail.com>",
138
149
  "Matthias Lösch <mlo@codiac.de>",
139
150
  "MONTOYA Damien <d.montoya@quadient.com>",
@@ -141,6 +152,7 @@
141
152
  "mrazauskas <tom@mrazauskas.de>",
142
153
  "Nancy <nancy@transit.app>",
143
154
  "Nezu S.A.S <nezu.ec@nezuecuador.com>",
155
+ "Nezu S.A.S <nezu.ec@nezuecuador.com>",
144
156
  "Nils Mehlhorn <nilsmehlhorn@users.noreply.github.com>",
145
157
  "notwonjang <venuscwj@naver.com>",
146
158
  "Nsambu E Namenda <greata576@gmail.com>",
@@ -159,16 +171,19 @@
159
171
  "rbrasco <roger.brasco@scytl.com>",
160
172
  "Rickard Lundén <rickard@winter.ax>",
161
173
  "Ricko Devian <rickodevian@gmail.com>",
174
+ "ricko-speedoc <ricko.devian@speedoc.com>",
162
175
  "RogueCode007 <abioyefeyifoluwa@gmail.com>",
163
176
  "Roman Hirsch <r.hirsch@brendow.de>",
164
177
  "RomanTheBrov <romouald.dombrovski@gmail.com>",
165
178
  "Ryan Duguid <ryanduguid@users.noreply.github.com>",
166
179
  "Ryan Gerry <gerryster@gmail.com>",
180
+ "Ryan Gerry <rgerry@bluemarblepayroll.com>",
167
181
  "swever826 <108704585+swever826@users.noreply.github.com>",
168
182
  "Sean Riley <spriley@msts.com>",
169
183
  "seb <sebastien@lewebfrancais.fr>",
170
184
  "Seb735 <duclutsebastien@yahoo.com>",
171
185
  "Simon Victory <email@simonvictory.com>",
186
+ "Simon Victory <email@simonvictory.com>",
172
187
  "Quennie <simply.me.queeny@gmail.com>",
173
188
  "swever826 <108704585+swever826@users.noreply.github.com>",
174
189
  "ThelenOliver <o.thelen@gastromatic.de>",
@@ -207,6 +222,7 @@
207
222
  "exports": {
208
223
  ".": {
209
224
  "types": "./types/index.d.ts",
225
+ "browser": "./src/browser.js",
210
226
  "import": "./src/index.js",
211
227
  "require": "./lib/index.cjs"
212
228
  },
@@ -220,7 +236,7 @@
220
236
  "module": "./src/index.js",
221
237
  "types": "./types/index.d.ts",
222
238
  "bin": {
223
- "holidays2json": "scripts/holidays2json.cjs"
239
+ "holidays2json": "scripts/holidays2json.js"
224
240
  },
225
241
  "directories": {
226
242
  "lib": "lib",
@@ -249,13 +265,12 @@
249
265
  "fixtures": "mocha test/all.mocha.js --writetests --countries",
250
266
  "lint": "eslint",
251
267
  "lint:fix": "eslint --fix",
252
- "prepare": "husky",
253
268
  "test": "mocha",
254
269
  "types": "tsc -p tsconfig.json && tsc -p tsconfig.test.json",
255
270
  "watch": "watch-run -p data/countries/*.yaml npm run yaml",
256
271
  "webpack": "webpack",
257
272
  "webpack:analyze": "webpack",
258
- "yaml": "node scripts/holidays2json.cjs"
273
+ "yaml": "node scripts/holidays2json.js"
259
274
  },
260
275
  "browserslist": [
261
276
  "> 1%",
@@ -268,23 +283,20 @@
268
283
  "reporter": "dot"
269
284
  },
270
285
  "dependencies": {
271
- "date-holidays-parser": "^3.7.0",
286
+ "caldate": "^3.0.0",
287
+ "date-holidays-parser": "^4.0.1",
272
288
  "js-yaml": "^5.5.0",
273
- "lodash": "^4.18.1",
274
- "prepin": "^1.0.3"
289
+ "lodash": "^4.18.1"
275
290
  },
276
291
  "devDependencies": {
277
292
  "@babel/core": "^8.1.5",
278
293
  "@babel/preset-env": "^8.1.5",
279
- "@commitlint/cli": "^21.3.0",
280
- "@commitlint/config-conventional": "^21.3.0",
281
294
  "@eslint/js": "^10.0.1",
282
295
  "@mocha/contributors": "git+https://github.com/commenthol/contributors.git#semver:1.1.0-0",
283
296
  "babel-loader": "^10.1.1",
284
297
  "eslint": "^10.16.0",
285
298
  "eslint-plugin-yml": "^3.10.1",
286
299
  "globals": "^17.15.0",
287
- "husky": "^9.1.7",
288
300
  "mocha": "^12.0.3",
289
301
  "npm-run-all2": "^9.1.0",
290
302
  "rimraf": "^6.1.4",
@@ -296,6 +308,6 @@
296
308
  "webpack-cli": "^7.3.1"
297
309
  },
298
310
  "engines": {
299
- "node": ">=12.0.0"
311
+ "node": ">=26.0.0"
300
312
  }
301
313
  }
@@ -0,0 +1,238 @@
1
+ #!/usr/bin/env node
2
+
3
+ import fs from "node:fs";
4
+ import path from "node:path";
5
+ import { fileURLToPath } from "node:url";
6
+ import { load } from "js-yaml";
7
+ import lodash from "lodash";
8
+
9
+ const { pick: _pick, omit: _omit } = lodash;
10
+ const scriptFile = fileURLToPath(import.meta.url);
11
+ const scriptDir = path.dirname(scriptFile);
12
+ const resolve = path.resolve;
13
+
14
+ const REGEX = /^([A-Z]+)\.yaml$/;
15
+
16
+ const CALENDAR_PLUGINS = {
17
+ EasterCalendarPlugin: /\b(easter|orthodox)\b/,
18
+ EquinoxCalendarPlugin: /\b(equinox|solstice)\b/,
19
+ HebrewCalendarPlugin:
20
+ /\b(Nisan|Iyyar|Sivan|Tamuz|Av|Elul|Tishrei|Cheshvan|Kislev|Tevet|Shvat|Adar)\b/,
21
+ HijriCalendarPlugin:
22
+ /\b(Muharram|Safar|Rabi al-awwal|Rabi al-thani|Jumada al-awwal|Jumada al-thani|Rajab|Shaban|Ramadan|Shawwal|Dhu al-Qidah|Dhu al-Hijjah)\b/,
23
+ JulianCalendarPlugin: /\bjulian\b/,
24
+ JalaaliCalendarPlugin:
25
+ /\b(Farvardin|Ordibehesht|Khordad|Tir|Mordad|Shahrivar|Mehr|Aban|Azar|Dey|Bahman|Esfand)\b/,
26
+ ChineseCalendarPlugin: /\b(chinese|vietnamese|korean)\b/,
27
+ BengaliRevisedCalendarPlugin: /\bbengali-revised\b/,
28
+ TibetanCalendarPlugin: /\b(tibetan|mongolian|bhutanese)\b/,
29
+ };
30
+
31
+ const config = {
32
+ dirname: resolve(scriptDir, "..", "data"),
33
+ countries: resolve(scriptDir, "..", "data", "countries"),
34
+ };
35
+
36
+ function Holidays2json(opts) {
37
+ this.opts = opts || {};
38
+ this.list = this.opts.list || [];
39
+ }
40
+ Holidays2json.prototype = {
41
+ /**
42
+ * get list of supported countries from directory
43
+ */
44
+ getList: function () {
45
+ let list = fs.readdirSync(config.countries);
46
+ list = list
47
+ .map((file) => {
48
+ if (REGEX.test(file)) {
49
+ return file.replace(REGEX, "$1");
50
+ } else {
51
+ return undefined;
52
+ }
53
+ })
54
+ .filter(function (file) {
55
+ return file;
56
+ })
57
+ .sort();
58
+ this.list = list;
59
+ return this;
60
+ },
61
+ /**
62
+ * load a single yaml file
63
+ */
64
+ load: function (cc, filename) {
65
+ filename = filename || resolve(config.countries, cc + ".yaml");
66
+ const data = fs.readFileSync(filename, "utf8");
67
+ const obj = load(data);
68
+ return obj;
69
+ },
70
+ /**
71
+ * build `holidays.json file`
72
+ */
73
+ build: function () {
74
+ const obj = this.load("0");
75
+ obj.holidays = {};
76
+ this.list.forEach(
77
+ function (cc) {
78
+ Object.assign(obj.holidays, this.load(cc).holidays);
79
+ }.bind(this),
80
+ );
81
+ Object.assign(obj, this.load(null, resolve(config.dirname, "names.yaml")));
82
+
83
+ if (this.opts.pick) {
84
+ obj.holidays = _pick(obj.holidays, this.opts.pick);
85
+ } else if (this.opts.omit) {
86
+ obj.holidays = _omit(obj.holidays, this.opts.omit);
87
+ }
88
+
89
+ obj.version = new Date().toISOString().replace(/^(.*)T.*$/, "$1");
90
+ this.holidays = obj;
91
+ if (this.opts.min) {
92
+ this.calendarPlugins = dive(obj)
93
+ }
94
+
95
+ return this;
96
+ },
97
+ /**
98
+ * save holidays
99
+ */
100
+ save: function () {
101
+ const json = JSON.stringify(this.holidays, null, 2) + "\n";
102
+ fs.writeFileSync(resolve(config.dirname, "holidays.json"), json, "utf8");
103
+ fs.writeFileSync(
104
+ resolve(scriptDir, "..", "src", "data.js"),
105
+ "export const data = " + json,
106
+ "utf8",
107
+ );
108
+
109
+ const plugins = this.calendarPlugins;
110
+ let source = "export { plugins } from 'date-holidays-parser/plugins'\n";
111
+ if (plugins?.length) {
112
+ const list = plugins.length ? `[\n ${plugins.join(",\n ")}\n]` : "[]";
113
+ const imports = plugins.map(function (plugin) {
114
+ return `import { ${plugin} } from 'date-holidays-parser/plugins/${plugin}'`;
115
+ });
116
+ source = [
117
+ ...imports,
118
+ ...(imports.length ? [""] : []),
119
+ `/** @type {import('date-holidays-parser').CalendarPlugin<unknown>[]} */`,
120
+ `export const plugins = ${list}`,
121
+ "",
122
+ ].join("\n");
123
+ }
124
+ fs.writeFileSync(
125
+ resolve(scriptDir, "..", "src", "plugins.js"),
126
+ source,
127
+ "utf8",
128
+ );
129
+
130
+ if (fs.existsSync(resolve(scriptDir, "..", "lib"))) {
131
+ fs.writeFileSync(
132
+ resolve(scriptDir, "..", "lib", "data.cjs"),
133
+ "exports.data = " + json,
134
+ "utf8",
135
+ );
136
+ if (plugins?.length) {
137
+ const plugins = this.calendarPlugins;
138
+ const list = plugins.length ? `[\n ${plugins.join(",\n ")}\n]` : "[]";
139
+ const requires = plugins.map(function (plugin) {
140
+ return `const { ${plugin} } = require('date-holidays-parser/plugins/${plugin}')`;
141
+ });
142
+ const commonjs = [
143
+ "'use strict'",
144
+ "",
145
+ ...requires,
146
+ ...(requires.length ? [""] : []),
147
+ `exports.plugins = ${list}`,
148
+ "",
149
+ ].join("\n");
150
+ fs.writeFileSync(
151
+ resolve(scriptDir, "..", "lib", "plugins.cjs"),
152
+ commonjs,
153
+ "utf8",
154
+ );
155
+ }
156
+ }
157
+ },
158
+ };
159
+ export default Holidays2json;
160
+
161
+ if (process.argv[1] && resolve(process.argv[1]) === scriptFile) {
162
+ const args = process.argv.splice(2);
163
+
164
+ const getOption = function (option) {
165
+ const i = args.indexOf(option);
166
+ if (i !== -1) {
167
+ const list = (args[i + 1] || "").toUpperCase().split(",").sort();
168
+ if (list && list.length) return list;
169
+ return true;
170
+ }
171
+ };
172
+
173
+ if (getOption("-h") || getOption("--help")) {
174
+ console.log(
175
+ [
176
+ "",
177
+ "holidays2json [options]",
178
+ "",
179
+ "translate holidays.yaml data to json",
180
+ "",
181
+ "-p|--pick comma separated list of countries to pick",
182
+ " from holidays.json file",
183
+ "-o|--omit comma separated list of countries to omit",
184
+ " from holidays.json file",
185
+ "-m|--min minimize to calendar plugins used in data",
186
+ " without --pick/--omit, preserve the current src/plugins.js list",
187
+ "",
188
+ "NOTE: There are some countries which depend on data of others which",
189
+ ' might render the file useless. e.g. "GU" requires "US", so try',
190
+ " to pick or omit both.",
191
+ "",
192
+ 'Use in your build process in package.json "scripts" section.',
193
+ ' "build" : "holidays2json -p US,CA,GU"',
194
+ "and run then with `npm run build`",
195
+ "",
196
+ ].join("\n "),
197
+ );
198
+ process.exit(0);
199
+ }
200
+
201
+ const opts = {
202
+ pick: getOption("--pick") || getOption("-p"),
203
+ omit: getOption("--omit") || getOption("-o"),
204
+ min: getOption("--min") || getOption("-m"),
205
+ };
206
+
207
+ new Holidays2json(opts).getList().build().save();
208
+ }
209
+
210
+ /**
211
+ * Find the CalendarPlugins required by the reduced data set.
212
+ */
213
+ function dive(data) {
214
+ const required = new Set();
215
+
216
+ const visit = function (data) {
217
+ switch (toString.call(data)) {
218
+ case "[object Object]":
219
+ Object.keys(data).forEach(function (key) {
220
+ if (key === "days") {
221
+ Object.keys(data[key]).forEach(function (rule) {
222
+ Object.keys(CALENDAR_PLUGINS).forEach(function (plugin) {
223
+ if (CALENDAR_PLUGINS[plugin].test(rule)) required.add(plugin);
224
+ });
225
+ });
226
+ } else {
227
+ visit(data[key]);
228
+ }
229
+ });
230
+ break;
231
+ }
232
+ };
233
+
234
+ visit(data);
235
+ return Object.keys(CALENDAR_PLUGINS).filter(function (plugin) {
236
+ return required.has(plugin);
237
+ });
238
+ }
package/src/Holidays.js CHANGED
@@ -4,19 +4,21 @@
4
4
  */
5
5
 
6
6
  import HolidaysParser from 'date-holidays-parser'
7
+ import { plugins } from './plugins.js'
7
8
 
8
9
  import { data } from './data.js'
9
10
 
10
11
  /** @typedef {import('date-holidays-parser').Location} Location */
11
- /** @typedef {import('date-holidays-parser').HolidayOptions} HolidayOptions */
12
+ /** @typedef {import('caldate').TimezoneAdapter} TimezoneAdapter */
13
+ /** @typedef {import('date-holidays-parser').HolidaysOptions} HolidaysOptions */
12
14
 
13
15
  /**
14
16
  * @class
15
17
  * @param {object} data - holiday data object - see data/holidays.json
16
- * @param {string|Location} [country] - country code or location object
17
- * @param {string} [state] - specifies state
18
- * @param {string} [region] - specifies region
19
- * @param {HolidayOptions} [opts] - options
18
+ * @param {string|Location|HolidaysOptions} [country] - country code, location object, or options
19
+ * @param {string|HolidaysOptions} [state] - state or options
20
+ * @param {string|HolidaysOptions} [region] - region or options
21
+ * @param {HolidaysOptions} [opts] - options
20
22
  * @example
21
23
  * ```js
22
24
  * new Holiday('US', 'la', 'no') // is the same as
@@ -24,8 +26,39 @@ import { data } from './data.js'
24
26
  * new Holiday({ country: 'us', state: 'la', region: 'no'})
25
27
  * ```
26
28
  */
27
- export class Holidays extends HolidaysParser {
29
+ export class HolidaysBase extends HolidaysParser {
30
+ /** @type {TimezoneAdapter|undefined} */
31
+ static defaultTimezoneAdapter
32
+
33
+ /**
34
+ * @param {string|Location|HolidaysOptions} [country]
35
+ * @param {string|HolidaysOptions} [state]
36
+ * @param {string|HolidaysOptions} [region]
37
+ * @param {HolidaysOptions} [opts]
38
+ */
28
39
  constructor (country, state, region, opts) {
40
+ if (region && typeof region === 'object') {
41
+ opts = region
42
+ region = undefined
43
+ } else if (state && typeof state === 'object') {
44
+ opts = state
45
+ state = undefined
46
+ } else if (
47
+ country &&
48
+ typeof country === 'object' &&
49
+ !('country' in country)
50
+ ) {
51
+ opts = country
52
+ country = undefined
53
+ }
54
+
55
+ opts = opts || {}
56
+ opts = {
57
+ ...opts,
58
+ plugins: opts.plugins === undefined ? plugins : opts.plugins,
59
+ timezoneAdapter:
60
+ opts.timezoneAdapter ?? /** @type {typeof HolidaysBase} */ (new.target).defaultTimezoneAdapter
61
+ }
29
62
  super(data, country, state, region, opts)
30
63
  }
31
64
  }
package/src/browser.js ADDED
@@ -0,0 +1,9 @@
1
+ import { temporalTimezoneAdapter } from 'caldate'
2
+ import { HolidaysBase } from './Holidays.js'
3
+
4
+ class Holidays extends HolidaysBase {
5
+ /** @type {import('caldate').TimezoneAdapter} */
6
+ static defaultTimezoneAdapter = temporalTimezoneAdapter
7
+ }
8
+
9
+ export default Holidays
package/src/index.js CHANGED
@@ -6,4 +6,12 @@
6
6
  /** @typedef {import('date-holidays-parser').HolidayMap} HolidayMap */
7
7
  /** @typedef {import('date-holidays-parser').HolidayType} HolidayType */
8
8
 
9
- export { Holidays as default } from "./Holidays.js";
9
+ import { momentTimezoneAdapter } from 'caldate/moment-timezone'
10
+ import { HolidaysBase } from './Holidays.js'
11
+
12
+ class Holidays extends HolidaysBase {
13
+ /** @type {import('caldate').TimezoneAdapter} */
14
+ static defaultTimezoneAdapter = momentTimezoneAdapter
15
+ }
16
+
17
+ export default Holidays
package/src/plugins.js ADDED
@@ -0,0 +1 @@
1
+ export { plugins } from 'date-holidays-parser/plugins'
package/types/index.d.ts CHANGED
@@ -21,6 +21,10 @@ declare module 'date-holidays' {
21
21
  * default ['observance', 'optional', 'school', 'bank', 'public']
22
22
  */
23
23
  types?: HolidayType[];
24
+ /** Calendar plugins enabled for this instance; omitted enables all built-ins. */
25
+ plugins?: import('date-holidays-parser').CalendarPlugin<unknown>[];
26
+ /** Timezone conversion implementation; defaults to moment-timezone in Node and Temporal in browsers. */
27
+ timezoneAdapter?: import('caldate').TimezoneAdapter;
24
28
  }
25
29
 
26
30
  export interface ActiveRange {