@fineanmol/public-holidays 1.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.
- package/LICENSE +21 -0
- package/README.md +65 -0
- package/package.json +46 -0
- package/src/data.js +49 -0
- package/src/index.d.ts +31 -0
- package/src/index.js +119 -0
package/LICENSE
ADDED
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
MIT License
|
|
2
|
+
|
|
3
|
+
Copyright (c) 2026 fineanmol
|
|
4
|
+
|
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
+
in the Software without restriction, including without limitation the rights
|
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
+
furnished to do so, subject to the following conditions:
|
|
11
|
+
|
|
12
|
+
The above copyright notice and this permission notice shall be included in all
|
|
13
|
+
copies or substantial portions of the Software.
|
|
14
|
+
|
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
+
SOFTWARE.
|
package/README.md
ADDED
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
# @fineanmol/public-holidays
|
|
2
|
+
|
|
3
|
+
Small, **zero-runtime-dependency** lookups for **public holidays** bundled as versioned data. Use it in Node or any bundler that supports ES modules.
|
|
4
|
+
|
|
5
|
+
**Pairs well with** [`@fineanmol/holiday-optimizer`](https://www.npmjs.com/package/@fineanmol/holiday-optimizer) for PTO planning.
|
|
6
|
+
|
|
7
|
+
## Install
|
|
8
|
+
|
|
9
|
+
```bash
|
|
10
|
+
npm install @fineanmol/public-holidays
|
|
11
|
+
```
|
|
12
|
+
|
|
13
|
+
## Regions
|
|
14
|
+
|
|
15
|
+
| `regionId` | Notes |
|
|
16
|
+
|--------------------|--------|
|
|
17
|
+
| `germany-berlin` | Berlin-specific days included where applicable |
|
|
18
|
+
| `india` | National / commonly observed set; **states differ** — confirm locally for payroll |
|
|
19
|
+
|
|
20
|
+
Data is shipped per **calendar year** in `src/data.js` (`byYear`). Add new years as you maintain the package.
|
|
21
|
+
|
|
22
|
+
## API
|
|
23
|
+
|
|
24
|
+
```js
|
|
25
|
+
import {
|
|
26
|
+
listRegions,
|
|
27
|
+
holidaysInYear,
|
|
28
|
+
isHoliday,
|
|
29
|
+
holidayOn,
|
|
30
|
+
nextHoliday,
|
|
31
|
+
previousHoliday,
|
|
32
|
+
toISODate,
|
|
33
|
+
} from "@fineanmol/public-holidays";
|
|
34
|
+
```
|
|
35
|
+
|
|
36
|
+
- **`listRegions()`** — `{ id, name }[]`
|
|
37
|
+
- **`holidaysInYear(regionId, year)`** — `{ date: 'YYYY-MM-DD', name }[]`
|
|
38
|
+
- **`isHoliday(date, regionId)`** — `boolean` (`date`: `Date` or ISO `YYYY-MM-DD`)
|
|
39
|
+
- **`holidayOn(date, regionId)`** — holiday object or `null`
|
|
40
|
+
- **`nextHoliday(fromDate, regionId)`** — first holiday **on or after** `fromDate`, or `null`
|
|
41
|
+
- **`previousHoliday(fromDate, regionId)`** — last holiday **on or before** `fromDate`, or `null`
|
|
42
|
+
- **`toISODate(date)`** — normalize to `YYYY-MM-DD` (local calendar day for `Date`)
|
|
43
|
+
|
|
44
|
+
## Example
|
|
45
|
+
|
|
46
|
+
```js
|
|
47
|
+
import { isHoliday, nextHoliday, holidaysInYear } from "@fineanmol/public-holidays";
|
|
48
|
+
|
|
49
|
+
holidaysInYear("germany-berlin", 2026).length;
|
|
50
|
+
// → 11
|
|
51
|
+
|
|
52
|
+
isHoliday("2026-10-03", "germany-berlin");
|
|
53
|
+
// → true
|
|
54
|
+
|
|
55
|
+
nextHoliday("2026-10-02", "germany-berlin");
|
|
56
|
+
// → { date: '2026-10-03', name: 'Tag der Deutschen Einheit' }
|
|
57
|
+
```
|
|
58
|
+
|
|
59
|
+
## Disclaimer
|
|
60
|
+
|
|
61
|
+
Holiday rules change. This package is for **apps and planning**, not legal or payroll advice. Verify official sources for compliance.
|
|
62
|
+
|
|
63
|
+
## License
|
|
64
|
+
|
|
65
|
+
MIT
|
package/package.json
ADDED
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@fineanmol/public-holidays",
|
|
3
|
+
"version": "1.0.0",
|
|
4
|
+
"description": "Zero-dependency public holiday lookups (Germany Berlin, India, …) with versioned yearly data.",
|
|
5
|
+
"type": "module",
|
|
6
|
+
"main": "./src/index.js",
|
|
7
|
+
"types": "./src/index.d.ts",
|
|
8
|
+
"exports": {
|
|
9
|
+
".": {
|
|
10
|
+
"types": "./src/index.d.ts",
|
|
11
|
+
"import": "./src/index.js",
|
|
12
|
+
"default": "./src/index.js"
|
|
13
|
+
}
|
|
14
|
+
},
|
|
15
|
+
"files": [
|
|
16
|
+
"src/index.js",
|
|
17
|
+
"src/index.d.ts",
|
|
18
|
+
"src/data.js",
|
|
19
|
+
"README.md",
|
|
20
|
+
"LICENSE"
|
|
21
|
+
],
|
|
22
|
+
"keywords": [
|
|
23
|
+
"holidays",
|
|
24
|
+
"public-holidays",
|
|
25
|
+
"calendar",
|
|
26
|
+
"india",
|
|
27
|
+
"germany",
|
|
28
|
+
"berlin",
|
|
29
|
+
"bank-holiday",
|
|
30
|
+
"pto"
|
|
31
|
+
],
|
|
32
|
+
"author": "fineanmol",
|
|
33
|
+
"license": "MIT",
|
|
34
|
+
"repository": {
|
|
35
|
+
"type": "git",
|
|
36
|
+
"url": "git+https://github.com/fineanmol/holiday-optimizer.git",
|
|
37
|
+
"directory": "packages/public-holidays"
|
|
38
|
+
},
|
|
39
|
+
"bugs": {
|
|
40
|
+
"url": "https://github.com/fineanmol/holiday-optimizer/issues"
|
|
41
|
+
},
|
|
42
|
+
"homepage": "https://github.com/fineanmol/holiday-optimizer/tree/main/packages/public-holidays#readme",
|
|
43
|
+
"publishConfig": {
|
|
44
|
+
"access": "public"
|
|
45
|
+
}
|
|
46
|
+
}
|
package/src/data.js
ADDED
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Versioned public-holiday tables. Extend `byYear` when you add a new calendar year.
|
|
3
|
+
* India list is a national / commonly observed set; states differ — verify locally.
|
|
4
|
+
*/
|
|
5
|
+
export const REGIONS = {
|
|
6
|
+
"germany-berlin": {
|
|
7
|
+
id: "germany-berlin",
|
|
8
|
+
name: "Germany (Berlin)",
|
|
9
|
+
byYear: {
|
|
10
|
+
2026: [
|
|
11
|
+
{ date: "2026-01-01", name: "Neujahr" },
|
|
12
|
+
{ date: "2026-03-08", name: "Internationaler Frauentag (Berlin)" },
|
|
13
|
+
{ date: "2026-04-03", name: "Karfreitag" },
|
|
14
|
+
{ date: "2026-04-06", name: "Ostermontag" },
|
|
15
|
+
{ date: "2026-05-01", name: "Tag der Arbeit" },
|
|
16
|
+
{ date: "2026-05-14", name: "Christi Himmelfahrt" },
|
|
17
|
+
{ date: "2026-05-25", name: "Pfingstmontag" },
|
|
18
|
+
{ date: "2026-10-03", name: "Tag der Deutschen Einheit" },
|
|
19
|
+
{ date: "2026-10-31", name: "Reformationstag (Berlin)" },
|
|
20
|
+
{ date: "2026-12-25", name: "1. Weihnachtstag" },
|
|
21
|
+
{ date: "2026-12-26", name: "2. Weihnachtstag" },
|
|
22
|
+
],
|
|
23
|
+
},
|
|
24
|
+
},
|
|
25
|
+
india: {
|
|
26
|
+
id: "india",
|
|
27
|
+
name: "India (national / commonly observed)",
|
|
28
|
+
byYear: {
|
|
29
|
+
2026: [
|
|
30
|
+
{ date: "2026-01-26", name: "Republic Day" },
|
|
31
|
+
{ date: "2026-03-08", name: "Holi" },
|
|
32
|
+
{ date: "2026-03-29", name: "Good Friday" },
|
|
33
|
+
{ date: "2026-04-14", name: "Ambedkar Jayanti" },
|
|
34
|
+
{ date: "2026-04-17", name: "Ram Navami" },
|
|
35
|
+
{ date: "2026-05-01", name: "Labour Day" },
|
|
36
|
+
{ date: "2026-06-17", name: "Eid ul-Fitr" },
|
|
37
|
+
{ date: "2026-08-15", name: "Independence Day" },
|
|
38
|
+
{ date: "2026-08-26", name: "Raksha Bandhan" },
|
|
39
|
+
{ date: "2026-09-05", name: "Janmashtami" },
|
|
40
|
+
{ date: "2026-10-02", name: "Gandhi Jayanti" },
|
|
41
|
+
{ date: "2026-10-12", name: "Dussehra" },
|
|
42
|
+
{ date: "2026-10-20", name: "Eid ul-Adha" },
|
|
43
|
+
{ date: "2026-10-29", name: "Diwali" },
|
|
44
|
+
{ date: "2026-11-14", name: "Guru Nanak Jayanti" },
|
|
45
|
+
{ date: "2026-12-25", name: "Christmas" },
|
|
46
|
+
],
|
|
47
|
+
},
|
|
48
|
+
},
|
|
49
|
+
};
|
package/src/index.d.ts
ADDED
|
@@ -0,0 +1,31 @@
|
|
|
1
|
+
export type Holiday = { date: string; name: string };
|
|
2
|
+
|
|
3
|
+
export type Region = {
|
|
4
|
+
id: string;
|
|
5
|
+
name: string;
|
|
6
|
+
byYear: Record<number, Holiday[]>;
|
|
7
|
+
};
|
|
8
|
+
|
|
9
|
+
export function toISODate(d: Date | string): string;
|
|
10
|
+
|
|
11
|
+
export function listRegions(): { id: string; name: string }[];
|
|
12
|
+
|
|
13
|
+
export function getRegion(regionId: string): Region | undefined;
|
|
14
|
+
|
|
15
|
+
export function holidaysInYear(regionId: string, year: number): Holiday[];
|
|
16
|
+
|
|
17
|
+
export function isHoliday(date: Date | string, regionId: string): boolean;
|
|
18
|
+
|
|
19
|
+
export function holidayOn(date: Date | string, regionId: string): Holiday | null;
|
|
20
|
+
|
|
21
|
+
export function nextHoliday(
|
|
22
|
+
fromDate: Date | string,
|
|
23
|
+
regionId: string
|
|
24
|
+
): Holiday | null;
|
|
25
|
+
|
|
26
|
+
export function previousHoliday(
|
|
27
|
+
fromDate: Date | string,
|
|
28
|
+
regionId: string
|
|
29
|
+
): Holiday | null;
|
|
30
|
+
|
|
31
|
+
export const REGIONS: Record<string, Region>;
|
package/src/index.js
ADDED
|
@@ -0,0 +1,119 @@
|
|
|
1
|
+
import { REGIONS } from "./data.js";
|
|
2
|
+
|
|
3
|
+
/** @typedef {{ date: string, name: string }} Holiday */
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* @param {Date | string} d
|
|
7
|
+
* @returns {string} YYYY-MM-DD (local calendar date when `Date` is used)
|
|
8
|
+
*/
|
|
9
|
+
export function toISODate(d) {
|
|
10
|
+
if (typeof d === "string") {
|
|
11
|
+
if (/^\d{4}-\d{2}-\d{2}$/.test(d)) return d;
|
|
12
|
+
throw new TypeError(`Expected ISO date string YYYY-MM-DD, got: ${d}`);
|
|
13
|
+
}
|
|
14
|
+
if (!(d instanceof Date) || Number.isNaN(d.getTime())) {
|
|
15
|
+
throw new TypeError("Expected a valid Date");
|
|
16
|
+
}
|
|
17
|
+
const y = d.getFullYear();
|
|
18
|
+
const m = String(d.getMonth() + 1).padStart(2, "0");
|
|
19
|
+
const day = String(d.getDate()).padStart(2, "0");
|
|
20
|
+
return `${y}-${m}-${day}`;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* @returns {{ id: string, name: string }[]}
|
|
25
|
+
*/
|
|
26
|
+
export function listRegions() {
|
|
27
|
+
return Object.values(REGIONS).map(({ id, name }) => ({ id, name }));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* @param {string} regionId
|
|
32
|
+
* @returns {{ id: string, name: string, byYear: Record<number, Holiday[]> } | undefined}
|
|
33
|
+
*/
|
|
34
|
+
export function getRegion(regionId) {
|
|
35
|
+
return REGIONS[regionId];
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
/**
|
|
39
|
+
* @param {string} regionId
|
|
40
|
+
* @param {number} year
|
|
41
|
+
* @returns {Holiday[]}
|
|
42
|
+
*/
|
|
43
|
+
export function holidaysInYear(regionId, year) {
|
|
44
|
+
const region = REGIONS[regionId];
|
|
45
|
+
if (!region) return [];
|
|
46
|
+
const list = region.byYear[year];
|
|
47
|
+
return list ? [...list] : [];
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
/**
|
|
51
|
+
* @param {Date | string} date
|
|
52
|
+
* @param {string} regionId
|
|
53
|
+
* @returns {boolean}
|
|
54
|
+
*/
|
|
55
|
+
export function isHoliday(date, regionId) {
|
|
56
|
+
return holidayOn(date, regionId) != null;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/**
|
|
60
|
+
* @param {Date | string} date
|
|
61
|
+
* @param {string} regionId
|
|
62
|
+
* @returns {Holiday | null}
|
|
63
|
+
*/
|
|
64
|
+
export function holidayOn(date, regionId) {
|
|
65
|
+
const iso = toISODate(date);
|
|
66
|
+
const year = Number(iso.slice(0, 4));
|
|
67
|
+
const list = holidaysInYear(regionId, year);
|
|
68
|
+
return list.find((h) => h.date === iso) ?? null;
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* First holiday on or after `fromDate` (inclusive), or `null` if none in bundled data.
|
|
73
|
+
* @param {Date | string} fromDate
|
|
74
|
+
* @param {string} regionId
|
|
75
|
+
* @returns {Holiday | null}
|
|
76
|
+
*/
|
|
77
|
+
export function nextHoliday(fromDate, regionId) {
|
|
78
|
+
const iso = toISODate(fromDate);
|
|
79
|
+
const region = REGIONS[regionId];
|
|
80
|
+
if (!region) return null;
|
|
81
|
+
|
|
82
|
+
/** @type {Holiday[]} */
|
|
83
|
+
let merged = [];
|
|
84
|
+
for (const y of Object.keys(region.byYear)
|
|
85
|
+
.map(Number)
|
|
86
|
+
.sort((a, b) => a - b)) {
|
|
87
|
+
merged = merged.concat(holidaysInYear(regionId, y));
|
|
88
|
+
}
|
|
89
|
+
merged.sort((a, b) => a.date.localeCompare(b.date));
|
|
90
|
+
return merged.find((h) => h.date >= iso) ?? null;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
/**
|
|
94
|
+
* Last holiday on or before `fromDate` (inclusive), or `null` if none in bundled data.
|
|
95
|
+
* @param {Date | string} fromDate
|
|
96
|
+
* @param {string} regionId
|
|
97
|
+
* @returns {Holiday | null}
|
|
98
|
+
*/
|
|
99
|
+
export function previousHoliday(fromDate, regionId) {
|
|
100
|
+
const iso = toISODate(fromDate);
|
|
101
|
+
const region = REGIONS[regionId];
|
|
102
|
+
if (!region) return null;
|
|
103
|
+
|
|
104
|
+
/** @type {Holiday[]} */
|
|
105
|
+
let merged = [];
|
|
106
|
+
for (const y of Object.keys(region.byYear)
|
|
107
|
+
.map(Number)
|
|
108
|
+
.sort((a, b) => a - b)) {
|
|
109
|
+
merged = merged.concat(holidaysInYear(regionId, y));
|
|
110
|
+
}
|
|
111
|
+
merged.sort((a, b) => a.date.localeCompare(b.date));
|
|
112
|
+
let last = null;
|
|
113
|
+
for (const h of merged) {
|
|
114
|
+
if (h.date <= iso) last = h;
|
|
115
|
+
}
|
|
116
|
+
return last;
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
export { REGIONS } from "./data.js";
|