dayjs-feiertage 0.0.1 → 0.1.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.
package/README.md CHANGED
@@ -1,74 +1,220 @@
1
1
  # dayjs-feiertage
2
2
 
3
-
4
- This is a wrapperlib for [feiertage.js](https://github.com/sfakir/feiertagejs) for dayjs to access German feiertage easily.
5
-
3
+ A dayjs plugin for German holidays (Feiertage) using [feiertagejs](https://github.com/sfakir/feiertagejs).
6
4
 
7
5
  ## Installation
8
6
 
9
- - [yarn](https://yarnpkg.com/en/): `yarn add dayjs-feiertage`
10
- - [npm](https://www.npmjs.com/): `npm install dayjs-feiertage`
7
+ ```bash
8
+ # pnpm
9
+ pnpm add dayjs-feiertage dayjs
10
+
11
+ # npm
12
+ npm install dayjs-feiertage dayjs
11
13
 
12
- ## Quick Examples
14
+ # yarn
15
+ yarn add dayjs-feiertage dayjs
16
+ ```
13
17
 
14
- ### ES Modules (Typescript/Javasript)
18
+ ## Quick Start
15
19
 
16
20
  ```javascript
17
- import dayjs from 'dayjs';
18
- import dayjsFeiertage from './src/dayjs-feiertage';
21
+ import dayjs from "dayjs";
22
+ import dayjsFeiertage from "dayjs-feiertage";
19
23
 
24
+ // Extend dayjs with the plugin
20
25
  dayjs.extend(dayjsFeiertage);
21
26
 
22
- dayjs('2020-12-25').isHoliday('BUND') // true
27
+ // Check if a date is a holiday
28
+ dayjs("2025-12-25").isHoliday("BUND"); // true
29
+
30
+ // Check if a date is a Sunday or holiday
31
+ dayjs("2025-12-25").isSunOrHoliday("BUND"); // true
32
+
33
+ // Get all holidays for a year
34
+ dayjs("2025-01-01").getHolidaysOfYear("BY"); // Array of Holiday objects
35
+ ```
36
+
37
+ ## API Reference
38
+
39
+ ### Instance Methods
40
+
41
+ #### `isHoliday(region: Region): boolean`
42
+
43
+ Check if the date is a holiday in the specified region.
44
+
45
+ ```javascript
46
+ dayjs("2025-12-25").isHoliday("BUND"); // true - Christmas
47
+ dayjs("2025-01-06").isHoliday("BW"); // true - Heilige Drei Könige (Baden-Württemberg)
48
+ dayjs("2025-01-06").isHoliday("NI"); // false - Not a holiday in Niedersachsen
49
+ ```
50
+
51
+ #### `isSunOrHoliday(region: Region): boolean`
23
52
 
24
- // check if a day is a specific holiday
25
- dayjs('2020-12-25').isSpecificHoliday( 'CHRISTIHIMMELFAHRT', 'ALL'); //false
53
+ Check if the date is a Sunday or a holiday in the specified region.
26
54
 
27
- dayjs('2020-12-25').getHolidaysOfYear( 'ALL'); // returns list of Holiday, see next nty
55
+ ```javascript
56
+ dayjs("2025-01-26").isSunOrHoliday("BUND"); // true - Sunday
57
+ dayjs("2025-12-25").isSunOrHoliday("BUND"); // true - Holiday
58
+ dayjs("2025-01-27").isSunOrHoliday("BUND"); // false - Regular Monday
28
59
  ```
29
60
 
30
- One entry of the array contains:
61
+ #### `isSpecificHoliday(holidayName: HolidayType, region?: Region): boolean`
62
+
63
+ Check if the date is a specific holiday. Region defaults to "ALL".
31
64
 
32
65
  ```javascript
33
- [{
34
- name: 'CHRISTIHIMMELFAHRT',
35
- date: new Date('2023-05-17T22:00:00.000Z'),
36
- dateString: '2023-05-18',
37
- regions: [
38
- 'BW', 'BY', 'BE',
39
- 'BB', 'HB', 'HE',
40
- 'HH', 'MV', 'NI',
41
- 'NW', 'RP', 'SL',
42
- 'SN', 'ST', 'SH',
43
- 'TH', 'BUND', 'AUGSBURG',
44
- 'ALL'
45
- ],
46
- translate: [Function: translate],
47
- getNormalizedDate: [Function: getNormalizedDate],
48
- equals: [Function: equals]
49
- }
50
- ]
66
+ dayjs("2025-05-29").isSpecificHoliday("CHRISTIHIMMELFAHRT"); // true
67
+ dayjs("2025-12-25").isSpecificHoliday("ERSTERWEIHNACHTSFEIERTAG", "BUND"); // true
68
+ dayjs("2025-10-03").isSpecificHoliday("DEUTSCHEEINHEIT"); // true
69
+ ```
51
70
 
71
+ #### `getHolidayByDate(region?: Region): Holiday | undefined`
72
+
73
+ Get the holiday object for this date. Returns `undefined` if not a holiday. Region defaults to "ALL".
74
+
75
+ ```javascript
76
+ const holiday = dayjs("2025-12-25").getHolidayByDate("BUND");
77
+ console.log(holiday?.name); // "ERSTERWEIHNACHTSFEIERTAG"
78
+ console.log(holiday?.translate("de")); // "Erster Weihnachtsfeiertag"
79
+ console.log(holiday?.dateString); // "2025-12-25"
52
80
  ```
53
81
 
54
- ## API doc
82
+ #### `getHolidaysOfYear(region: Region): Holiday[]`
55
83
 
56
- The full API doc can be found [here](docs.md).
84
+ Get all holidays for the year of this date in the specified region.
85
+
86
+ ```javascript
87
+ const holidays = dayjs("2025-01-01").getHolidaysOfYear("BUND");
88
+ holidays.forEach((h) => {
89
+ console.log(`${h.dateString}: ${h.translate("de")}`);
90
+ });
91
+ ```
57
92
 
58
- ## Feedback and Questions
93
+ ### Static Methods
59
94
 
60
- You have two options two give feedback or ask questions:
95
+ #### `dayjs.addHolidayTranslation(isoCode: string, translation: TranslationTable): void`
61
96
 
62
- - Comment the official release [post](https://fakir.tech/de/feiertage-js-deutsche-feiertage-fuer-node-js-und-browser-javascript/)
63
- - Open issues or pullrequests on [github](https://github.com/sfakir/feiertagejs)
97
+ Add custom translations for holiday names.
64
98
 
65
- ## Contributors
99
+ ```javascript
100
+ dayjs.addHolidayTranslation("en", {
101
+ NEUJAHRSTAG: "New Year's Day",
102
+ ERSTERWEIHNACHTSFEIERTAG: "Christmas Day",
103
+ CHRISTIHIMMELFAHRT: "Ascension Day",
104
+ });
105
+ ```
106
+
107
+ #### `dayjs.setHolidayLanguage(lng: string): void`
108
+
109
+ Set the default language for holiday translations.
110
+
111
+ ```javascript
112
+ dayjs.setHolidayLanguage("en");
113
+ ```
114
+
115
+ #### `dayjs.getHolidayLanguage(): string`
116
+
117
+ Get the currently set language.
118
+
119
+ ```javascript
120
+ console.log(dayjs.getHolidayLanguage()); // "de"
121
+ ```
122
+
123
+ ## Types
124
+
125
+ ### Region
126
+
127
+ German state codes and special regions:
128
+
129
+ | Code | State/Region |
130
+ | --------- | ----------------------------- |
131
+ | `BW` | Baden-Württemberg |
132
+ | `BY` | Bavaria (Bayern) |
133
+ | `BE` | Berlin |
134
+ | `BB` | Brandenburg |
135
+ | `HB` | Bremen |
136
+ | `HH` | Hamburg |
137
+ | `HE` | Hesse (Hessen) |
138
+ | `MV` | Mecklenburg-Vorpommern |
139
+ | `NI` | Lower Saxony (Niedersachsen) |
140
+ | `NW` | North Rhine-Westphalia |
141
+ | `RP` | Rhineland-Palatinate |
142
+ | `SL` | Saarland |
143
+ | `SN` | Saxony (Sachsen) |
144
+ | `ST` | Saxony-Anhalt |
145
+ | `SH` | Schleswig-Holstein |
146
+ | `TH` | Thuringia (Thüringen) |
147
+ | `BUND` | Nationwide holidays only |
148
+ | `ALL` | All holidays (any region) |
149
+ | `AUGSBURG`| City of Augsburg |
150
+
151
+ ### HolidayType
152
+
153
+ Available holiday identifiers:
154
+
155
+ - `NEUJAHRSTAG` - New Year's Day
156
+ - `HEILIGEDREIKOENIGE` - Epiphany
157
+ - `KARFREITAG` - Good Friday
158
+ - `OSTERSONNTAG` - Easter Sunday
159
+ - `OSTERMONTAG` - Easter Monday
160
+ - `TAG_DER_ARBEIT` - Labour Day
161
+ - `CHRISTIHIMMELFAHRT` - Ascension Day
162
+ - `PFINGSTSONNTAG` - Whit Sunday
163
+ - `PFINGSTMONTAG` - Whit Monday
164
+ - `FRONLEICHNAM` - Corpus Christi
165
+ - `MARIAHIMMELFAHRT` - Assumption of Mary
166
+ - `DEUTSCHEEINHEIT` - German Unity Day
167
+ - `REFORMATIONSTAG` - Reformation Day
168
+ - `ALLERHEILIGEN` - All Saints' Day
169
+ - `BUBETAG` - Day of Repentance and Prayer
170
+ - `ERSTERWEIHNACHTSFEIERTAG` - Christmas Day
171
+ - `ZWEITERWEIHNACHTSFEIERTAG` - Boxing Day
172
+ - `WELTKINDERTAG` - World Children's Day
173
+ - `WELTFRAUENTAG` - International Women's Day
174
+ - `AUGSBURGER_FRIEDENSFEST` - Augsburg Peace Festival
175
+
176
+ ### Holiday Object
177
+
178
+ ```typescript
179
+ interface Holiday {
180
+ name: HolidayType;
181
+ date: Date;
182
+ dateString: string; // YYYY-MM-DD format
183
+ regions: Region[];
184
+ translate(lang?: string): string | undefined;
185
+ equals(date: Date): boolean;
186
+ getNormalizedDate(): number;
187
+ }
188
+ ```
189
+
190
+ ## Timezone Handling
191
+
192
+ All dates are interpreted in German timezone (Europe/Berlin). The underlying feiertagejs library automatically converts any Date object to German timezone before checking holidays.
193
+
194
+ ## Development
195
+
196
+ ```bash
197
+ # Install dependencies
198
+ pnpm install
199
+
200
+ # Run tests
201
+ pnpm test
202
+
203
+ # Run tests in watch mode
204
+ pnpm test:watch
205
+
206
+ # Build
207
+ pnpm build
208
+
209
+ # Type check
210
+ pnpm lint
211
+ ```
66
212
 
67
- Thank you for contributing:
213
+ ## License
68
214
 
69
- - thetric
70
- - SteveOswald
215
+ MIT
71
216
 
72
- ## Feedback
217
+ ## Related
73
218
 
74
- If you have any questions, feel free to open an issue.
219
+ - [feiertagejs](https://github.com/sfakir/feiertagejs) - The underlying library for German holiday calculations
220
+ - [dayjs](https://day.js.org/) - Fast 2kB alternative to Moment.js
@@ -0,0 +1,55 @@
1
+ import { PluginFunc } from 'dayjs';
2
+ import { Region, HolidayType, Holiday } from 'feiertagejs';
3
+ export { Holiday, HolidayType, Region } from 'feiertagejs';
4
+
5
+ type TranslationTable = Partial<Record<HolidayType, string>>;
6
+ declare module "dayjs" {
7
+ interface Dayjs {
8
+ /**
9
+ * Check if the date is a holiday in the specified region
10
+ * @param region - German state code (e.g., 'BY', 'NW') or 'BUND' or 'ALL'
11
+ */
12
+ isHoliday(region: Region): boolean;
13
+ /**
14
+ * Check if the date is a Sunday or a holiday in the specified region
15
+ * @param region - German state code (e.g., 'BY', 'NW') or 'BUND' or 'ALL'
16
+ */
17
+ isSunOrHoliday(region: Region): boolean;
18
+ /**
19
+ * Check if the date is a specific holiday
20
+ * @param holidayName - The holiday type (e.g., 'CHRISTIHIMMELFAHRT')
21
+ * @param region - German state code (e.g., 'BY', 'NW') or 'BUND' or 'ALL'
22
+ */
23
+ isSpecificHoliday(holidayName: HolidayType, region?: Region): boolean;
24
+ /**
25
+ * Get the holiday object for this date if it is a holiday
26
+ * @param region - German state code (e.g., 'BY', 'NW') or 'BUND' or 'ALL'
27
+ */
28
+ getHolidayByDate(region?: Region): Holiday | undefined;
29
+ /**
30
+ * Get all holidays for the year of this date
31
+ * @param region - German state code (e.g., 'BY', 'NW') or 'BUND' or 'ALL'
32
+ */
33
+ getHolidaysOfYear(region: Region): Holiday[];
34
+ }
35
+ interface DayjsStatic {
36
+ /**
37
+ * Add a translation for holiday names
38
+ * @param isoCode - Language code (e.g., 'en', 'fr')
39
+ * @param translation - Map of HolidayType to translated string
40
+ */
41
+ addHolidayTranslation(isoCode: string, translation: TranslationTable): void;
42
+ /**
43
+ * Set the default language for holiday translations
44
+ * @param lng - Language code (e.g., 'de', 'en')
45
+ */
46
+ setHolidayLanguage(lng: string): void;
47
+ /**
48
+ * Get the currently set language for holiday translations
49
+ */
50
+ getHolidayLanguage(): string;
51
+ }
52
+ }
53
+ declare const dayjsFeiertage: PluginFunc;
54
+
55
+ export { type TranslationTable, dayjsFeiertage as default };
@@ -0,0 +1,55 @@
1
+ import { PluginFunc } from 'dayjs';
2
+ import { Region, HolidayType, Holiday } from 'feiertagejs';
3
+ export { Holiday, HolidayType, Region } from 'feiertagejs';
4
+
5
+ type TranslationTable = Partial<Record<HolidayType, string>>;
6
+ declare module "dayjs" {
7
+ interface Dayjs {
8
+ /**
9
+ * Check if the date is a holiday in the specified region
10
+ * @param region - German state code (e.g., 'BY', 'NW') or 'BUND' or 'ALL'
11
+ */
12
+ isHoliday(region: Region): boolean;
13
+ /**
14
+ * Check if the date is a Sunday or a holiday in the specified region
15
+ * @param region - German state code (e.g., 'BY', 'NW') or 'BUND' or 'ALL'
16
+ */
17
+ isSunOrHoliday(region: Region): boolean;
18
+ /**
19
+ * Check if the date is a specific holiday
20
+ * @param holidayName - The holiday type (e.g., 'CHRISTIHIMMELFAHRT')
21
+ * @param region - German state code (e.g., 'BY', 'NW') or 'BUND' or 'ALL'
22
+ */
23
+ isSpecificHoliday(holidayName: HolidayType, region?: Region): boolean;
24
+ /**
25
+ * Get the holiday object for this date if it is a holiday
26
+ * @param region - German state code (e.g., 'BY', 'NW') or 'BUND' or 'ALL'
27
+ */
28
+ getHolidayByDate(region?: Region): Holiday | undefined;
29
+ /**
30
+ * Get all holidays for the year of this date
31
+ * @param region - German state code (e.g., 'BY', 'NW') or 'BUND' or 'ALL'
32
+ */
33
+ getHolidaysOfYear(region: Region): Holiday[];
34
+ }
35
+ interface DayjsStatic {
36
+ /**
37
+ * Add a translation for holiday names
38
+ * @param isoCode - Language code (e.g., 'en', 'fr')
39
+ * @param translation - Map of HolidayType to translated string
40
+ */
41
+ addHolidayTranslation(isoCode: string, translation: TranslationTable): void;
42
+ /**
43
+ * Set the default language for holiday translations
44
+ * @param lng - Language code (e.g., 'de', 'en')
45
+ */
46
+ setHolidayLanguage(lng: string): void;
47
+ /**
48
+ * Get the currently set language for holiday translations
49
+ */
50
+ getHolidayLanguage(): string;
51
+ }
52
+ }
53
+ declare const dayjsFeiertage: PluginFunc;
54
+
55
+ export { type TranslationTable, dayjsFeiertage as default };
@@ -1,3 +1,4 @@
1
+ "use strict";
1
2
  var __defProp = Object.defineProperty;
2
3
  var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
3
4
  var __getOwnPropNames = Object.getOwnPropertyNames;
@@ -23,18 +24,32 @@ __export(dayjs_feiertage_exports, {
23
24
  });
24
25
  module.exports = __toCommonJS(dayjs_feiertage_exports);
25
26
  var import_feiertagejs = require("feiertagejs");
26
- var dayjs_feiertage_default = (option = {}, dayjsClass) => {
27
+ var dayjsFeiertage = (_option, dayjsClass, dayjsFactory) => {
27
28
  dayjsClass.prototype.isHoliday = function(region) {
28
29
  return (0, import_feiertagejs.isHoliday)(this.toDate(), region);
29
30
  };
30
- dayjsClass.prototype.isSpecificHoliday = function(holidayName, region) {
31
- return (0, import_feiertagejs.isSpecificHoliday)(this.toDate(), holidayName, region);
32
- };
33
31
  dayjsClass.prototype.isSunOrHoliday = function(region) {
34
32
  return (0, import_feiertagejs.isSunOrHoliday)(this.toDate(), region);
35
33
  };
34
+ dayjsClass.prototype.isSpecificHoliday = function(holidayName, region = "ALL") {
35
+ return (0, import_feiertagejs.isSpecificHoliday)(this.toDate(), holidayName, region);
36
+ };
37
+ dayjsClass.prototype.getHolidayByDate = function(region = "ALL") {
38
+ return (0, import_feiertagejs.getHolidayByDate)(this.toDate(), region) || void 0;
39
+ };
36
40
  dayjsClass.prototype.getHolidaysOfYear = function(region) {
37
41
  return (0, import_feiertagejs.getHolidays)(this.year(), region);
38
42
  };
43
+ const factory = dayjsFactory;
44
+ factory.addHolidayTranslation = (isoCode, translation) => {
45
+ (0, import_feiertagejs.addTranslation)(isoCode, translation);
46
+ };
47
+ factory.setHolidayLanguage = (lng) => {
48
+ (0, import_feiertagejs.setLanguage)(lng);
49
+ };
50
+ factory.getHolidayLanguage = () => {
51
+ return (0, import_feiertagejs.getLanguage)();
52
+ };
39
53
  };
54
+ var dayjs_feiertage_default = dayjsFeiertage;
40
55
  //# sourceMappingURL=dayjs-feiertage.js.map
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/dayjs-feiertage.ts"],"sourcesContent":["import {\n getHolidays,\n Holiday,\n HolidayType,\n isHoliday,\n isSpecificHoliday,\n isSunOrHoliday,\n Region,\n} from \"feiertagejs\";\n\n// add custom plugin to dayjs' types\ndeclare module \"dayjs\" {\n interface Dayjs {\n isSunOrHoliday(region: Region): boolean;\n isHoliday(region: Region): boolean;\n isSpecificHoliday(holidayName: string, region: Region): boolean;\n getHolidaysOfYear(region: Region): Holiday[];\n \n }\n}\n\nexport default (option = {}, dayjsClass) => {\n dayjsClass.prototype.isHoliday = function (region: Region | null): boolean {\n return isHoliday(this.toDate(), region);\n };\n dayjsClass.prototype.isSpecificHoliday = function (\n holidayName: HolidayType,\n region: Region\n ) {\n return isSpecificHoliday(this.toDate(), holidayName, region);\n };\n dayjsClass.prototype.isSunOrHoliday = function (region: Region): boolean {\n return isSunOrHoliday(this.toDate(), region);\n };\n dayjsClass.prototype.getHolidaysOfYear = function (\n region: Region\n ): Holiday[] {\n return getHolidays(this.year(), region);\n };\n};\n"],"mappings":";;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AAAA,yBAQO;AAaP,IAAO,0BAAQ,CAAC,SAAS,CAAC,GAAG,eAAe;AAC1C,aAAW,UAAU,YAAY,SAAU,QAAgC;AACzE,eAAO,8BAAU,KAAK,OAAO,GAAG,MAAM;AAAA,EACxC;AACA,aAAW,UAAU,oBAAoB,SACvC,aACA,QACA;AACA,eAAO,sCAAkB,KAAK,OAAO,GAAG,aAAa,MAAM;AAAA,EAC7D;AACA,aAAW,UAAU,iBAAiB,SAAU,QAAyB;AACvE,eAAO,mCAAe,KAAK,OAAO,GAAG,MAAM;AAAA,EAC7C;AACA,aAAW,UAAU,oBAAoB,SACvC,QACW;AACX,eAAO,gCAAY,KAAK,KAAK,GAAG,MAAM;AAAA,EACxC;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/dayjs-feiertage.ts"],"sourcesContent":["import type { PluginFunc } from \"dayjs\";\nimport {\n getHolidays,\n getHolidayByDate,\n Holiday,\n HolidayType,\n isHoliday,\n isSpecificHoliday,\n isSunOrHoliday,\n Region,\n addTranslation,\n setLanguage,\n getLanguage,\n} from \"feiertagejs\";\n\n// Re-export types for consumers\nexport type { Holiday, HolidayType, Region } from \"feiertagejs\";\n\n// TranslationTable type (partial record of HolidayType to string)\nexport type TranslationTable = Partial<Record<HolidayType, string>>;\n\n// Augment dayjs module with plugin methods\ndeclare module \"dayjs\" {\n interface Dayjs {\n /**\n * Check if the date is a holiday in the specified region\n * @param region - German state code (e.g., 'BY', 'NW') or 'BUND' or 'ALL'\n */\n isHoliday(region: Region): boolean;\n\n /**\n * Check if the date is a Sunday or a holiday in the specified region\n * @param region - German state code (e.g., 'BY', 'NW') or 'BUND' or 'ALL'\n */\n isSunOrHoliday(region: Region): boolean;\n\n /**\n * Check if the date is a specific holiday\n * @param holidayName - The holiday type (e.g., 'CHRISTIHIMMELFAHRT')\n * @param region - German state code (e.g., 'BY', 'NW') or 'BUND' or 'ALL'\n */\n isSpecificHoliday(holidayName: HolidayType, region?: Region): boolean;\n\n /**\n * Get the holiday object for this date if it is a holiday\n * @param region - German state code (e.g., 'BY', 'NW') or 'BUND' or 'ALL'\n */\n getHolidayByDate(region?: Region): Holiday | undefined;\n\n /**\n * Get all holidays for the year of this date\n * @param region - German state code (e.g., 'BY', 'NW') or 'BUND' or 'ALL'\n */\n getHolidaysOfYear(region: Region): Holiday[];\n }\n\n // Static methods on dayjs\n interface DayjsStatic {\n /**\n * Add a translation for holiday names\n * @param isoCode - Language code (e.g., 'en', 'fr')\n * @param translation - Map of HolidayType to translated string\n */\n addHolidayTranslation(isoCode: string, translation: TranslationTable): void;\n\n /**\n * Set the default language for holiday translations\n * @param lng - Language code (e.g., 'de', 'en')\n */\n setHolidayLanguage(lng: string): void;\n\n /**\n * Get the currently set language for holiday translations\n */\n getHolidayLanguage(): string;\n }\n}\n\n// Define the interface for dayjsFactory to include static methods\ninterface DayjsFactory {\n addHolidayTranslation: (isoCode: string, translation: TranslationTable) => void;\n setHolidayLanguage: (lng: string) => void;\n getHolidayLanguage: () => string;\n}\n\nconst dayjsFeiertage: PluginFunc = (_option, dayjsClass, dayjsFactory) => {\n // Instance methods\n dayjsClass.prototype.isHoliday = function (region: Region): boolean {\n return isHoliday(this.toDate(), region);\n };\n\n dayjsClass.prototype.isSunOrHoliday = function (region: Region): boolean {\n return isSunOrHoliday(this.toDate(), region);\n };\n\n dayjsClass.prototype.isSpecificHoliday = function (\n holidayName: HolidayType,\n region: Region = \"ALL\"\n ): boolean {\n return isSpecificHoliday(this.toDate(), holidayName, region);\n };\n\n dayjsClass.prototype.getHolidayByDate = function (\n region: Region = \"ALL\"\n ): Holiday | undefined {\n return getHolidayByDate(this.toDate(), region) || undefined;\n };\n\n dayjsClass.prototype.getHolidaysOfYear = function (region: Region): Holiday[] {\n return getHolidays(this.year(), region);\n };\n\n // Static methods on dayjs factory\n const factory = dayjsFactory as unknown as DayjsFactory;\n\n factory.addHolidayTranslation = (\n isoCode: string,\n translation: TranslationTable\n ): void => {\n addTranslation(isoCode, translation);\n };\n\n factory.setHolidayLanguage = (lng: string): void => {\n setLanguage(lng);\n };\n\n factory.getHolidayLanguage = (): string => {\n return getLanguage();\n };\n};\n\nexport default dayjsFeiertage;\n"],"mappings":";;;;;;;;;;;;;;;;;;;;AAAA;AAAA;AAAA;AAAA;AAAA;AACA,yBAYO;AAwEP,IAAM,iBAA6B,CAAC,SAAS,YAAY,iBAAiB;AAExE,aAAW,UAAU,YAAY,SAAU,QAAyB;AAClE,eAAO,8BAAU,KAAK,OAAO,GAAG,MAAM;AAAA,EACxC;AAEA,aAAW,UAAU,iBAAiB,SAAU,QAAyB;AACvE,eAAO,mCAAe,KAAK,OAAO,GAAG,MAAM;AAAA,EAC7C;AAEA,aAAW,UAAU,oBAAoB,SACvC,aACA,SAAiB,OACR;AACT,eAAO,sCAAkB,KAAK,OAAO,GAAG,aAAa,MAAM;AAAA,EAC7D;AAEA,aAAW,UAAU,mBAAmB,SACtC,SAAiB,OACI;AACrB,eAAO,qCAAiB,KAAK,OAAO,GAAG,MAAM,KAAK;AAAA,EACpD;AAEA,aAAW,UAAU,oBAAoB,SAAU,QAA2B;AAC5E,eAAO,gCAAY,KAAK,KAAK,GAAG,MAAM;AAAA,EACxC;AAGA,QAAM,UAAU;AAEhB,UAAQ,wBAAwB,CAC9B,SACA,gBACS;AACT,2CAAe,SAAS,WAAW;AAAA,EACrC;AAEA,UAAQ,qBAAqB,CAAC,QAAsB;AAClD,wCAAY,GAAG;AAAA,EACjB;AAEA,UAAQ,qBAAqB,MAAc;AACzC,eAAO,gCAAY;AAAA,EACrB;AACF;AAEA,IAAO,0BAAQ;","names":[]}
@@ -1,24 +1,42 @@
1
1
  // src/dayjs-feiertage.ts
2
2
  import {
3
3
  getHolidays,
4
+ getHolidayByDate,
4
5
  isHoliday,
5
6
  isSpecificHoliday,
6
- isSunOrHoliday
7
+ isSunOrHoliday,
8
+ addTranslation,
9
+ setLanguage,
10
+ getLanguage
7
11
  } from "feiertagejs";
8
- var dayjs_feiertage_default = (option = {}, dayjsClass) => {
12
+ var dayjsFeiertage = (_option, dayjsClass, dayjsFactory) => {
9
13
  dayjsClass.prototype.isHoliday = function(region) {
10
14
  return isHoliday(this.toDate(), region);
11
15
  };
12
- dayjsClass.prototype.isSpecificHoliday = function(holidayName, region) {
13
- return isSpecificHoliday(this.toDate(), holidayName, region);
14
- };
15
16
  dayjsClass.prototype.isSunOrHoliday = function(region) {
16
17
  return isSunOrHoliday(this.toDate(), region);
17
18
  };
19
+ dayjsClass.prototype.isSpecificHoliday = function(holidayName, region = "ALL") {
20
+ return isSpecificHoliday(this.toDate(), holidayName, region);
21
+ };
22
+ dayjsClass.prototype.getHolidayByDate = function(region = "ALL") {
23
+ return getHolidayByDate(this.toDate(), region) || void 0;
24
+ };
18
25
  dayjsClass.prototype.getHolidaysOfYear = function(region) {
19
26
  return getHolidays(this.year(), region);
20
27
  };
28
+ const factory = dayjsFactory;
29
+ factory.addHolidayTranslation = (isoCode, translation) => {
30
+ addTranslation(isoCode, translation);
31
+ };
32
+ factory.setHolidayLanguage = (lng) => {
33
+ setLanguage(lng);
34
+ };
35
+ factory.getHolidayLanguage = () => {
36
+ return getLanguage();
37
+ };
21
38
  };
39
+ var dayjs_feiertage_default = dayjsFeiertage;
22
40
  export {
23
41
  dayjs_feiertage_default as default
24
42
  };
@@ -1 +1 @@
1
- {"version":3,"sources":["../src/dayjs-feiertage.ts"],"sourcesContent":["import {\n getHolidays,\n Holiday,\n HolidayType,\n isHoliday,\n isSpecificHoliday,\n isSunOrHoliday,\n Region,\n} from \"feiertagejs\";\n\n// add custom plugin to dayjs' types\ndeclare module \"dayjs\" {\n interface Dayjs {\n isSunOrHoliday(region: Region): boolean;\n isHoliday(region: Region): boolean;\n isSpecificHoliday(holidayName: string, region: Region): boolean;\n getHolidaysOfYear(region: Region): Holiday[];\n \n }\n}\n\nexport default (option = {}, dayjsClass) => {\n dayjsClass.prototype.isHoliday = function (region: Region | null): boolean {\n return isHoliday(this.toDate(), region);\n };\n dayjsClass.prototype.isSpecificHoliday = function (\n holidayName: HolidayType,\n region: Region\n ) {\n return isSpecificHoliday(this.toDate(), holidayName, region);\n };\n dayjsClass.prototype.isSunOrHoliday = function (region: Region): boolean {\n return isSunOrHoliday(this.toDate(), region);\n };\n dayjsClass.prototype.getHolidaysOfYear = function (\n region: Region\n ): Holiday[] {\n return getHolidays(this.year(), region);\n };\n};\n"],"mappings":";AAAA;AAAA,EACE;AAAA,EAGA;AAAA,EACA;AAAA,EACA;AAAA,OAEK;AAaP,IAAO,0BAAQ,CAAC,SAAS,CAAC,GAAG,eAAe;AAC1C,aAAW,UAAU,YAAY,SAAU,QAAgC;AACzE,WAAO,UAAU,KAAK,OAAO,GAAG,MAAM;AAAA,EACxC;AACA,aAAW,UAAU,oBAAoB,SACvC,aACA,QACA;AACA,WAAO,kBAAkB,KAAK,OAAO,GAAG,aAAa,MAAM;AAAA,EAC7D;AACA,aAAW,UAAU,iBAAiB,SAAU,QAAyB;AACvE,WAAO,eAAe,KAAK,OAAO,GAAG,MAAM;AAAA,EAC7C;AACA,aAAW,UAAU,oBAAoB,SACvC,QACW;AACX,WAAO,YAAY,KAAK,KAAK,GAAG,MAAM;AAAA,EACxC;AACF;","names":[]}
1
+ {"version":3,"sources":["../src/dayjs-feiertage.ts"],"sourcesContent":["import type { PluginFunc } from \"dayjs\";\nimport {\n getHolidays,\n getHolidayByDate,\n Holiday,\n HolidayType,\n isHoliday,\n isSpecificHoliday,\n isSunOrHoliday,\n Region,\n addTranslation,\n setLanguage,\n getLanguage,\n} from \"feiertagejs\";\n\n// Re-export types for consumers\nexport type { Holiday, HolidayType, Region } from \"feiertagejs\";\n\n// TranslationTable type (partial record of HolidayType to string)\nexport type TranslationTable = Partial<Record<HolidayType, string>>;\n\n// Augment dayjs module with plugin methods\ndeclare module \"dayjs\" {\n interface Dayjs {\n /**\n * Check if the date is a holiday in the specified region\n * @param region - German state code (e.g., 'BY', 'NW') or 'BUND' or 'ALL'\n */\n isHoliday(region: Region): boolean;\n\n /**\n * Check if the date is a Sunday or a holiday in the specified region\n * @param region - German state code (e.g., 'BY', 'NW') or 'BUND' or 'ALL'\n */\n isSunOrHoliday(region: Region): boolean;\n\n /**\n * Check if the date is a specific holiday\n * @param holidayName - The holiday type (e.g., 'CHRISTIHIMMELFAHRT')\n * @param region - German state code (e.g., 'BY', 'NW') or 'BUND' or 'ALL'\n */\n isSpecificHoliday(holidayName: HolidayType, region?: Region): boolean;\n\n /**\n * Get the holiday object for this date if it is a holiday\n * @param region - German state code (e.g., 'BY', 'NW') or 'BUND' or 'ALL'\n */\n getHolidayByDate(region?: Region): Holiday | undefined;\n\n /**\n * Get all holidays for the year of this date\n * @param region - German state code (e.g., 'BY', 'NW') or 'BUND' or 'ALL'\n */\n getHolidaysOfYear(region: Region): Holiday[];\n }\n\n // Static methods on dayjs\n interface DayjsStatic {\n /**\n * Add a translation for holiday names\n * @param isoCode - Language code (e.g., 'en', 'fr')\n * @param translation - Map of HolidayType to translated string\n */\n addHolidayTranslation(isoCode: string, translation: TranslationTable): void;\n\n /**\n * Set the default language for holiday translations\n * @param lng - Language code (e.g., 'de', 'en')\n */\n setHolidayLanguage(lng: string): void;\n\n /**\n * Get the currently set language for holiday translations\n */\n getHolidayLanguage(): string;\n }\n}\n\n// Define the interface for dayjsFactory to include static methods\ninterface DayjsFactory {\n addHolidayTranslation: (isoCode: string, translation: TranslationTable) => void;\n setHolidayLanguage: (lng: string) => void;\n getHolidayLanguage: () => string;\n}\n\nconst dayjsFeiertage: PluginFunc = (_option, dayjsClass, dayjsFactory) => {\n // Instance methods\n dayjsClass.prototype.isHoliday = function (region: Region): boolean {\n return isHoliday(this.toDate(), region);\n };\n\n dayjsClass.prototype.isSunOrHoliday = function (region: Region): boolean {\n return isSunOrHoliday(this.toDate(), region);\n };\n\n dayjsClass.prototype.isSpecificHoliday = function (\n holidayName: HolidayType,\n region: Region = \"ALL\"\n ): boolean {\n return isSpecificHoliday(this.toDate(), holidayName, region);\n };\n\n dayjsClass.prototype.getHolidayByDate = function (\n region: Region = \"ALL\"\n ): Holiday | undefined {\n return getHolidayByDate(this.toDate(), region) || undefined;\n };\n\n dayjsClass.prototype.getHolidaysOfYear = function (region: Region): Holiday[] {\n return getHolidays(this.year(), region);\n };\n\n // Static methods on dayjs factory\n const factory = dayjsFactory as unknown as DayjsFactory;\n\n factory.addHolidayTranslation = (\n isoCode: string,\n translation: TranslationTable\n ): void => {\n addTranslation(isoCode, translation);\n };\n\n factory.setHolidayLanguage = (lng: string): void => {\n setLanguage(lng);\n };\n\n factory.getHolidayLanguage = (): string => {\n return getLanguage();\n };\n};\n\nexport default dayjsFeiertage;\n"],"mappings":";AACA;AAAA,EACE;AAAA,EACA;AAAA,EAGA;AAAA,EACA;AAAA,EACA;AAAA,EAEA;AAAA,EACA;AAAA,EACA;AAAA,OACK;AAwEP,IAAM,iBAA6B,CAAC,SAAS,YAAY,iBAAiB;AAExE,aAAW,UAAU,YAAY,SAAU,QAAyB;AAClE,WAAO,UAAU,KAAK,OAAO,GAAG,MAAM;AAAA,EACxC;AAEA,aAAW,UAAU,iBAAiB,SAAU,QAAyB;AACvE,WAAO,eAAe,KAAK,OAAO,GAAG,MAAM;AAAA,EAC7C;AAEA,aAAW,UAAU,oBAAoB,SACvC,aACA,SAAiB,OACR;AACT,WAAO,kBAAkB,KAAK,OAAO,GAAG,aAAa,MAAM;AAAA,EAC7D;AAEA,aAAW,UAAU,mBAAmB,SACtC,SAAiB,OACI;AACrB,WAAO,iBAAiB,KAAK,OAAO,GAAG,MAAM,KAAK;AAAA,EACpD;AAEA,aAAW,UAAU,oBAAoB,SAAU,QAA2B;AAC5E,WAAO,YAAY,KAAK,KAAK,GAAG,MAAM;AAAA,EACxC;AAGA,QAAM,UAAU;AAEhB,UAAQ,wBAAwB,CAC9B,SACA,gBACS;AACT,mBAAe,SAAS,WAAW;AAAA,EACrC;AAEA,UAAQ,qBAAqB,CAAC,QAAsB;AAClD,gBAAY,GAAG;AAAA,EACjB;AAEA,UAAQ,qBAAqB,MAAc;AACzC,WAAO,YAAY;AAAA,EACrB;AACF;AAEA,IAAO,0BAAQ;","names":[]}
package/package.json CHANGED
@@ -1,28 +1,60 @@
1
1
  {
2
2
  "name": "dayjs-feiertage",
3
- "version": "0.0.1",
4
- "description": "",
5
- "main": "./dist/index.js",
6
- "module": "./dist/index.mjs",
7
- "types": "./dist/index.d.ts",
3
+ "version": "0.1.0",
4
+ "description": "A dayjs plugin for German holidays (Feiertage) using feiertagejs",
5
+ "main": "./dist/dayjs-feiertage.js",
6
+ "module": "./dist/dayjs-feiertage.mjs",
7
+ "types": "./dist/dayjs-feiertage.d.ts",
8
+ "exports": {
9
+ ".": {
10
+ "import": {
11
+ "types": "./dist/dayjs-feiertage.d.mts",
12
+ "default": "./dist/dayjs-feiertage.mjs"
13
+ },
14
+ "require": {
15
+ "types": "./dist/dayjs-feiertage.d.ts",
16
+ "default": "./dist/dayjs-feiertage.js"
17
+ }
18
+ }
19
+ },
8
20
  "files": [
9
21
  "dist"
10
22
  ],
11
- "scripts": {
12
- "build": "tsup",
13
- "test": "jest"
23
+ "keywords": [
24
+ "dayjs",
25
+ "plugin",
26
+ "feiertage",
27
+ "holidays",
28
+ "german",
29
+ "germany",
30
+ "feiertagejs"
31
+ ],
32
+ "author": "Simon Fakir",
33
+ "license": "MIT",
34
+ "repository": {
35
+ "type": "git",
36
+ "url": "git+https://github.com/sfakir/dayjs-feiertage.git"
37
+ },
38
+ "bugs": {
39
+ "url": "https://github.com/sfakir/dayjs-feiertage/issues"
40
+ },
41
+ "homepage": "https://github.com/sfakir/dayjs-feiertage#readme",
42
+ "peerDependencies": {
43
+ "dayjs": ">=1.11.0"
14
44
  },
15
- "author": "",
16
- "license": "ISC",
17
45
  "dependencies": {
18
- "dayjs": "^1.11.10",
19
46
  "feiertagejs": "^1.4.0"
20
47
  },
21
48
  "devDependencies": {
22
- "@types/jest": "^29.5.11",
23
- "jest": "^29.7.0",
24
- "ts-jest": "^29.1.1",
49
+ "dayjs": "^1.11.10",
25
50
  "tsup": "^8.0.1",
26
- "typescipt": "^1.0.0"
51
+ "typescript": "^5.3.0",
52
+ "vitest": "^1.2.0"
53
+ },
54
+ "scripts": {
55
+ "build": "tsup",
56
+ "test": "vitest run",
57
+ "test:watch": "vitest",
58
+ "lint": "tsc --noEmit"
27
59
  }
28
- }
60
+ }