date-holidays 3.39.2 → 4.0.0

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.
Files changed (87) hide show
  1. package/README.md +8 -4
  2. package/data/countries/AF.todo +78 -0
  3. package/data/countries/AI.yaml +3 -2
  4. package/data/countries/AQ.todo +18 -0
  5. package/data/countries/BD.yaml +3 -3
  6. package/data/countries/BS.yaml +7 -1
  7. package/data/countries/BT.todo +50 -0
  8. package/data/countries/BV.todo +11 -0
  9. package/data/countries/CN.yaml +480 -7
  10. package/data/countries/CP.todo +11 -0
  11. package/data/countries/DG.todo +10 -0
  12. package/data/countries/DO.yaml +2 -1
  13. package/data/countries/EC.yaml +108 -5
  14. package/data/countries/FK.todo +9 -0
  15. package/data/countries/FM.todo +20 -0
  16. package/data/countries/GB.yaml +4 -0
  17. package/data/countries/GS.todo +9 -0
  18. package/data/countries/HM.todo +10 -0
  19. package/data/countries/ID.yaml +33 -0
  20. package/data/countries/IO.todo +9 -0
  21. package/data/countries/IQ.todo +46 -0
  22. package/data/countries/JO.todo +34 -0
  23. package/data/countries/JP.yaml +10 -0
  24. package/data/countries/KG.todo +28 -0
  25. package/data/countries/KH.todo +60 -0
  26. package/data/countries/KI.todo +18 -0
  27. package/data/countries/KP.todo +32 -0
  28. package/data/countries/KR.yaml +14 -0
  29. package/data/countries/KW.todo +22 -0
  30. package/data/countries/LA.todo +46 -0
  31. package/data/countries/LB.todo +26 -0
  32. package/data/countries/MH.todo +65 -0
  33. package/data/countries/MM.todo +40 -0
  34. package/data/countries/MN.todo +56 -0
  35. package/data/countries/MO.todo +9 -0
  36. package/data/countries/MP.todo +9 -0
  37. package/data/countries/MV.todo +73 -0
  38. package/data/countries/NP.todo +53 -0
  39. package/data/countries/NR.todo +38 -0
  40. package/data/countries/NU.todo +9 -0
  41. package/data/countries/OM.todo +32 -0
  42. package/data/countries/PG.todo +55 -0
  43. package/data/countries/PN.todo +9 -0
  44. package/data/countries/PS.todo +43 -0
  45. package/data/countries/PW.todo +42 -0
  46. package/data/countries/QA.todo +24 -0
  47. package/data/countries/SB.todo +30 -0
  48. package/data/countries/SG.yaml +1 -1
  49. package/data/countries/SY.todo +38 -0
  50. package/data/countries/TF.todo +11 -0
  51. package/data/countries/TJ.todo +18 -0
  52. package/data/countries/TK.todo +9 -0
  53. package/data/countries/TL.todo +36 -0
  54. package/data/countries/TM.todo +22 -0
  55. package/data/countries/TR.yaml +16 -2
  56. package/data/countries/TV.todo +26 -0
  57. package/data/countries/TW.yaml +124 -14
  58. package/data/countries/TZ.yaml +3 -2
  59. package/data/countries/UM.todo +30 -0
  60. package/data/countries/VC.yaml +2 -2
  61. package/data/countries/WS.todo +32 -0
  62. package/data/countries/YE.todo +54 -0
  63. package/data/countries/ZW.yaml +2 -1
  64. package/data/holidays.json +1249 -147
  65. package/data/names.yaml +1 -1
  66. package/dist/index.min.js +1 -1
  67. package/dist/index.min.js.LICENSE.txt +0 -18
  68. package/dist/index.min.js.map +1 -1
  69. package/dist/umd.min.js +1 -1
  70. package/dist/umd.min.js.LICENSE.txt +0 -18
  71. package/dist/umd.min.js.map +1 -1
  72. package/lib/Holidays.cjs +40 -7
  73. package/lib/data.cjs +1249 -147
  74. package/lib/index.cjs +15 -2
  75. package/package.json +51 -21
  76. package/scripts/holidays2json.js +238 -0
  77. package/src/Holidays.js +39 -6
  78. package/src/browser.js +9 -0
  79. package/src/data.js +1249 -147
  80. package/src/index.js +9 -1
  81. package/src/plugins.js +1 -0
  82. package/types/index.d.ts +4 -0
  83. package/CHANGELOG.md +0 -1411
  84. package/eslint.config.mjs +0 -50
  85. package/scripts/holidays2json.cjs +0 -197
  86. package/tsconfig.json +0 -19
  87. package/tsconfig.test.json +0 -11
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.39.2",
3
+ "version": "4.0.0",
4
4
  "description": "worldwide holidays",
5
5
  "keywords": [
6
6
  "holidays",
@@ -25,16 +25,20 @@
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
+ "Anubhav <anubhavlal.15@gmail.com>",
35
38
  "Artem Yagutyan <artem.yagutyan@gmail.com>",
36
39
  "Artur Kraft <arkraft@users.noreply.github.com>",
37
40
  "ash <makingahabit@gmail.com>",
41
+ "Asım Mirza Çiftler <asimmirzac@gmail.com>",
38
42
  "ben <99397608+benkhong@users.noreply.github.com>",
39
43
  "Ben Arwin <github@arwin.net>",
40
44
  "Bilal Gültekin <bilal@Bilals-MacBook-Pro.local>",
@@ -54,6 +58,7 @@
54
58
  "damon02 <damon@teqplay.nl>",
55
59
  "David Hedlund <davidhedlund@users.noreply.github.com>",
56
60
  "David Álvarez Navarro <david16an@gmail.com>",
61
+ "dbdefault <246079841+dbdefault@users.noreply.github.com>",
57
62
  "Diego Henrique Oliveira <contato@diegoholiveira.com>",
58
63
  "Dominik Bruhn <dominik@menlo79.com>",
59
64
  "DrunkenCloud <drunkencloud99@gmail.com>",
@@ -61,9 +66,11 @@
61
66
  "Emanuel Hoogeveen <emanuel@medweb.nl>",
62
67
  "Emmanuel GBAVOU <egbavou32@gmail.com>",
63
68
  "Erlend Ellingsen <erlend.ame@gmail.com>",
69
+ "Faraz S. A. <345765971+FSA-G@users.noreply.github.com>",
64
70
  "fasteg <eg.lee@fastfive.co.kr>",
65
71
  "Filip Staffa <fstaffa@cimpress.com>",
66
72
  "Florian SALEUR <dev.daedalus@gmail.com>",
73
+ "Florian SALEUR <dev.daedalus@gmail.com>",
67
74
  "Francesco Ansanelli <f.ansanelli@solution-g.com>",
68
75
  "g1mn <16727837+g1mn@users.noreply.github.com>",
69
76
  "Gabor Borus <gabor.borus@gmail.com>",
@@ -83,6 +90,7 @@
83
90
  "Humam Aziz Romdhoni <anaktampan@live.com>",
84
91
  "hweejae-shin <hwejae25@gmail.com>",
85
92
  "Ihor Haiduk <cookkycok@gmail.com>",
93
+ "Ilyasse <ilyassesalama7@gmail.com>",
86
94
  "Ilyasse Salama <46769766+ilyassesalama@users.noreply.github.com>",
87
95
  "Ing.Norante <eppedema@gmail.com>",
88
96
  "Jack Zhang <18542127+jk1z@users.noreply.github.com>",
@@ -90,16 +98,20 @@
90
98
  "JAlexander <roodrallec@users.noreply.github.com>",
91
99
  "James Dixon <jim.w.dixon@gmail.com>",
92
100
  "Jani Šumak <jani.sumak@inova.si>",
101
+ "Jay Hemnani <193022578+jayhemnani9910@users.noreply.github.com>",
93
102
  "Jeff Hughes <43132199+jwh-hutchison@users.noreply.github.com>",
94
103
  "Jérôme Vasseur <jerome.vasseur@thetribe.io>",
95
104
  "Jesús <jesus.gonzalez.novez@deskbird.com>",
96
105
  "jhordyess <dev@jhordyess.com>",
106
+ "jjohnnystwsss <33243683+jjohnnystwsss@users.noreply.github.com>",
97
107
  "jk-12345 <33206139+jk-12345@users.noreply.github.com>",
98
108
  "John-Olav Storvold <johsto@knowit.no>",
99
109
  "JohnBelly95 <john_@DESKTOP-B80I05V.localdomain>",
100
110
  "jordanfodera <jordan@humaans.io>",
101
111
  "Jørgen Kalsnes Hagen <43886029+Snailedlt@users.noreply.github.com>",
102
112
  "Josh Luongo <josh@yumait.com.au>",
113
+ "Josh Luongo <joshluongo@me.com>",
114
+ "Joshua Rippon <j.rippon@rocketlab.co.nz>",
103
115
  "Joshua Rippon <joshuarippon1@gmail.com>",
104
116
  "Jukka Lehtimäki <jukka.lehtimaki@atoz.fi>",
105
117
  "Julian Krenge <julian@parcellab.com>",
@@ -107,14 +119,18 @@
107
119
  "Karl Horky <karl.horky@gmail.com>",
108
120
  "Kerstens Maxim <maxim.kerstens@gmail.com>",
109
121
  "Kevin Ley <3976145+kevinley@users.noreply.github.com>",
122
+ "Kevin Ley <kevin@salonkee.lu>",
110
123
  "Kevin Ley <ley.kevin@icloud.com>",
111
124
  "Kevin Samoei <samoeikev@gmail.com>",
112
125
  "Kiernan McColl <kiernan@kzn.io>",
126
+ "Kipkoech Noah <noahtrevorrono@gmail.com>",
113
127
  "Konstantinos Koukourakis <konstantinoskouk90@gmail.com>",
114
128
  "Kristjan ESPERANTO <35647502+KristjanESPERANTO@users.noreply.github.com>",
115
129
  "Lê Minh Tuấn <tuan.lm@open-dev.io>",
116
130
  "Leonidas Villeneuve <leonidas@leonidasv.com>",
131
+ "Liu Hangjiang <lhj1118pzh@live.cn>",
117
132
  "loicngrlwf <private@loicnogier.fr>",
133
+ "Long Nguyen <olragon@gmail.com>",
118
134
  "Long Nguyen <olragon@users.noreply.github.com>",
119
135
  "Lorenzo Breda <lorenzo.breda@net.va>",
120
136
  "Lukas Eipert <git@leipert.io>",
@@ -126,13 +142,17 @@
126
142
  "Maty <35110087+M4TY@users.noreply.github.com>",
127
143
  "Matyáš Himmer <matyhimmer@gmail.com>",
128
144
  "Mauro Braggio <m.braggio@e-time.it>",
145
+ "mehlhorn <mail@nils-mehlhorn.de>",
129
146
  "mirobimbo <mirobimbo@gmail.com>",
130
147
  "Matthias Lösch <mlo@codiac.de>",
131
148
  "MONTOYA Damien <d.montoya@quadient.com>",
149
+ "Mradul Singh <msingh@dealmeridian.com>",
132
150
  "mrazauskas <tom@mrazauskas.de>",
133
151
  "Nancy <nancy@transit.app>",
134
152
  "Nezu S.A.S <nezu.ec@nezuecuador.com>",
153
+ "Nezu S.A.S <nezu.ec@nezuecuador.com>",
135
154
  "Nils Mehlhorn <nilsmehlhorn@users.noreply.github.com>",
155
+ "notwonjang <venuscwj@naver.com>",
136
156
  "Nsambu E Namenda <greata576@gmail.com>",
137
157
  "omicron <ben@theangleco.com>",
138
158
  "oprogramador <uomodislesia@gmail.com>",
@@ -144,20 +164,24 @@
144
164
  "Philip Renich <hello@philiprenich.com>",
145
165
  "oprogramador <uomodislesia@gmail.com>",
146
166
  "PPsyrius <19505219+PPsyrius@users.noreply.github.com>",
167
+ "QuantIntellect <195442302+QuantIntellect@users.noreply.github.com>",
147
168
  "r.ryngenen@gmail.com <r.ryngenen@gmail.com>",
148
169
  "rbrasco <roger.brasco@scytl.com>",
149
170
  "Rickard Lundén <rickard@winter.ax>",
150
171
  "Ricko Devian <rickodevian@gmail.com>",
172
+ "ricko-speedoc <ricko.devian@speedoc.com>",
151
173
  "RogueCode007 <abioyefeyifoluwa@gmail.com>",
152
174
  "Roman Hirsch <r.hirsch@brendow.de>",
153
175
  "RomanTheBrov <romouald.dombrovski@gmail.com>",
154
176
  "Ryan Duguid <ryanduguid@users.noreply.github.com>",
155
177
  "Ryan Gerry <gerryster@gmail.com>",
178
+ "Ryan Gerry <rgerry@bluemarblepayroll.com>",
156
179
  "swever826 <108704585+swever826@users.noreply.github.com>",
157
180
  "Sean Riley <spriley@msts.com>",
158
181
  "seb <sebastien@lewebfrancais.fr>",
159
182
  "Seb735 <duclutsebastien@yahoo.com>",
160
183
  "Simon Victory <email@simonvictory.com>",
184
+ "Simon Victory <email@simonvictory.com>",
161
185
  "Quennie <simply.me.queeny@gmail.com>",
162
186
  "swever826 <108704585+swever826@users.noreply.github.com>",
163
187
  "ThelenOliver <o.thelen@gastromatic.de>",
@@ -169,6 +193,7 @@
169
193
  "Tomas Masnik <tomas.masnik@coworkers.ai>",
170
194
  "Tomasz Swistak <swistak.tomasz@outlook.com>",
171
195
  "tothadi <tothadam.onp@gmail.com>",
196
+ "trackoor <55851864+trackoor@users.noreply.github.com>",
172
197
  "Tristan Drummond <tristdrum@gmail.com>",
173
198
  "Troels Bay-Petersen <troels.petersen@hr-on.com>",
174
199
  "Vansh Vats <vishu.vats2007@gmail.com>",
@@ -195,6 +220,7 @@
195
220
  "exports": {
196
221
  ".": {
197
222
  "types": "./types/index.d.ts",
223
+ "browser": "./src/browser.js",
198
224
  "import": "./src/index.js",
199
225
  "require": "./lib/index.cjs"
200
226
  },
@@ -208,13 +234,21 @@
208
234
  "module": "./src/index.js",
209
235
  "types": "./types/index.d.ts",
210
236
  "bin": {
211
- "holidays2json": "scripts/holidays2json.cjs"
237
+ "holidays2json": "scripts/holidays2json.js"
212
238
  },
213
239
  "directories": {
214
240
  "lib": "lib",
215
241
  "doc": "docs",
216
242
  "test": "test"
217
243
  },
244
+ "files": [
245
+ "data",
246
+ "dist",
247
+ "lib",
248
+ "scripts/holidays2json.js",
249
+ "src",
250
+ "types"
251
+ ],
218
252
  "scripts": {
219
253
  "all": "run-s clean build lint test doc:tree doc:attrib webpack",
220
254
  "build": "run-s yaml build:only",
@@ -226,16 +260,15 @@
226
260
  "clean:modules": "rimraf node_modules",
227
261
  "doc:attrib": "node scripts/attributions.cjs",
228
262
  "doc:tree": "node scripts/addtree.cjs",
263
+ "fixtures": "mocha test/all.mocha.js --writetests --countries",
229
264
  "lint": "eslint",
230
265
  "lint:fix": "eslint --fix",
231
- "fixtures": "mocha test/all.mocha.js --writetests --countries",
232
266
  "test": "mocha",
267
+ "types": "tsc -p tsconfig.json && tsc -p tsconfig.test.json",
233
268
  "watch": "watch-run -p data/countries/*.yaml npm run yaml",
234
269
  "webpack": "webpack",
235
270
  "webpack:analyze": "webpack",
236
- "yaml": "node scripts/holidays2json.cjs",
237
- "prepare": "husky",
238
- "types": "tsc -p tsconfig.json && tsc -p tsconfig.test.json"
271
+ "yaml": "node scripts/holidays2json.js"
239
272
  },
240
273
  "browserslist": [
241
274
  "> 1%",
@@ -248,34 +281,31 @@
248
281
  "reporter": "dot"
249
282
  },
250
283
  "dependencies": {
251
- "date-holidays-parser": "^3.7.0",
284
+ "caldate": "^3.0.0",
285
+ "date-holidays-parser": "^4.0.0",
252
286
  "js-yaml": "^5.5.0",
253
- "lodash": "^4.18.1",
254
- "prepin": "^1.0.3"
287
+ "lodash": "^4.18.1"
255
288
  },
256
289
  "devDependencies": {
257
- "@babel/core": "^8.1.0",
258
- "@babel/preset-env": "^8.0.7",
259
- "@commitlint/cli": "^21.2.4",
260
- "@commitlint/config-conventional": "^21.2.4",
290
+ "@babel/core": "^8.1.4",
291
+ "@babel/preset-env": "^8.1.4",
261
292
  "@eslint/js": "^10.0.1",
262
293
  "@mocha/contributors": "git+https://github.com/commenthol/contributors.git#semver:1.1.0-0",
263
294
  "babel-loader": "^10.1.1",
264
- "eslint": "^10.14.0",
265
- "eslint-plugin-yml": "^3.10.0",
295
+ "eslint": "^10.16.0",
296
+ "eslint-plugin-yml": "^3.10.1",
266
297
  "globals": "^17.14.0",
267
- "husky": "^9.1.7",
268
298
  "mocha": "^12.0.3",
269
- "npm-run-all2": "^9.0.4",
299
+ "npm-run-all2": "^9.1.0",
270
300
  "rimraf": "^6.1.4",
271
- "rollup": "^4.68.0",
301
+ "rollup": "^4.69.0",
272
302
  "typescript": "^7.0.2",
273
303
  "watch-run": "^1.2.5",
274
- "webpack": "^5.112.2",
275
- "webpack-bundle-analyzer": "^5.4.2",
304
+ "webpack": "^5.113.0",
305
+ "webpack-bundle-analyzer": "^5.4.3",
276
306
  "webpack-cli": "^7.3.1"
277
307
  },
278
308
  "engines": {
279
- "node": ">=12.0.0"
309
+ "node": ">=26.0.0"
280
310
  }
281
311
  }
@@ -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