colombian-holidays 5.0.3 → 5.0.5

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,9 +1,6 @@
1
1
  # Colombian Holidays 🎆
2
2
 
3
3
  [![npm version](https://badge.fury.io/js/colombian-holidays.svg)](https://badge.fury.io/js/colombian-holidays)
4
- [![codecov](https://codecov.io/gh/MauricioRobayo/colombian-holidays/branch/master/graph/badge.svg)](https://codecov.io/gh/MauricioRobayo/colombian-holidays)
5
- [![CodeFactor](https://www.codefactor.io/repository/github/mauriciorobayo/colombian-holidays/badge)](https://www.codefactor.io/repository/github/mauriciorobayo/colombian-holidays)
6
- [![](https://badgen.net/badge/Run%20with%20/VS%20Code/5B3ADF?icon=https://runme.dev/img/logo.svg)](git@github.com:MauricioRobayo/colombian-holidays.git)
7
4
 
8
5
  TypeScript module to calculate colombian holidays for any given year.
9
6
 
@@ -0,0 +1,62 @@
1
+ interface BasicHoliday {
2
+ name: {
3
+ en: string;
4
+ es: string;
5
+ };
6
+ nextMonday: boolean;
7
+ }
8
+ interface ColombianHoliday extends BasicHoliday {
9
+ date: string;
10
+ celebrationDate: string;
11
+ }
12
+ interface ColombianHolidayWithNativeDate extends BasicHoliday {
13
+ date: Date;
14
+ celebrationDate: Date;
15
+ }
16
+
17
+ declare function getHolidaysForYear(year: number, options?: {
18
+ valueAsDate: false | undefined;
19
+ }): ColombianHoliday[];
20
+ declare function getHolidaysForYear(year: number, options?: {
21
+ valueAsDate: true;
22
+ }): ColombianHolidayWithNativeDate[];
23
+
24
+ declare function isHoliday(date: Date): boolean;
25
+
26
+ declare function holidaysWithinInterval(options: {
27
+ start: Date;
28
+ end: Date;
29
+ valueAsDate: false | undefined;
30
+ }): ColombianHoliday[];
31
+ declare function holidaysWithinInterval(options: {
32
+ start: Date;
33
+ end: Date;
34
+ valueAsDate: true;
35
+ }): ColombianHolidayWithNativeDate[];
36
+ declare function holidaysWithinInterval(options: {
37
+ start: Date;
38
+ end: Date;
39
+ valueAsDate?: boolean;
40
+ }): ColombianHoliday[] | ColombianHolidayWithNativeDate[];
41
+
42
+ declare const FIRST_HOLIDAY_YEAR = 1583;
43
+ declare const LAST_HOLIDAY_YEAR = 4099;
44
+ type MonthNumbers = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
45
+ type Month = MonthNumbers | Omit<number, MonthNumbers>;
46
+ declare function colombianHolidays(options?: undefined | {
47
+ year?: number;
48
+ month?: Month;
49
+ valueAsDate: false | undefined;
50
+ }): ColombianHoliday[];
51
+ declare function colombianHolidays(options?: {
52
+ year?: number;
53
+ month?: Month;
54
+ valueAsDate: true;
55
+ }): ColombianHolidayWithNativeDate[];
56
+ declare function colombianHolidays(options?: {
57
+ year?: number;
58
+ month?: Month;
59
+ valueAsDate?: boolean;
60
+ }): ColombianHoliday[] | ColombianHolidayWithNativeDate[];
61
+
62
+ export { FIRST_HOLIDAY_YEAR, LAST_HOLIDAY_YEAR, type Month, colombianHolidays, colombianHolidays as default, getHolidaysForYear, holidaysWithinInterval, isHoliday };
package/dist/index.d.ts CHANGED
@@ -1,24 +1,62 @@
1
- import { ColombianHoliday, ColombianHolidayWithNativeDate } from "./types";
2
- export declare const FIRST_HOLIDAY_YEAR = 1583;
3
- export declare const LAST_HOLIDAY_YEAR = 4099;
1
+ interface BasicHoliday {
2
+ name: {
3
+ en: string;
4
+ es: string;
5
+ };
6
+ nextMonday: boolean;
7
+ }
8
+ interface ColombianHoliday extends BasicHoliday {
9
+ date: string;
10
+ celebrationDate: string;
11
+ }
12
+ interface ColombianHolidayWithNativeDate extends BasicHoliday {
13
+ date: Date;
14
+ celebrationDate: Date;
15
+ }
16
+
17
+ declare function getHolidaysForYear(year: number, options?: {
18
+ valueAsDate: false | undefined;
19
+ }): ColombianHoliday[];
20
+ declare function getHolidaysForYear(year: number, options?: {
21
+ valueAsDate: true;
22
+ }): ColombianHolidayWithNativeDate[];
23
+
24
+ declare function isHoliday(date: Date): boolean;
25
+
26
+ declare function holidaysWithinInterval(options: {
27
+ start: Date;
28
+ end: Date;
29
+ valueAsDate: false | undefined;
30
+ }): ColombianHoliday[];
31
+ declare function holidaysWithinInterval(options: {
32
+ start: Date;
33
+ end: Date;
34
+ valueAsDate: true;
35
+ }): ColombianHolidayWithNativeDate[];
36
+ declare function holidaysWithinInterval(options: {
37
+ start: Date;
38
+ end: Date;
39
+ valueAsDate?: boolean;
40
+ }): ColombianHoliday[] | ColombianHolidayWithNativeDate[];
41
+
42
+ declare const FIRST_HOLIDAY_YEAR = 1583;
43
+ declare const LAST_HOLIDAY_YEAR = 4099;
4
44
  type MonthNumbers = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12;
5
- export type Month = MonthNumbers | Omit<number, MonthNumbers>;
6
- export declare function colombianHolidays(options?: undefined | {
45
+ type Month = MonthNumbers | Omit<number, MonthNumbers>;
46
+ declare function colombianHolidays(options?: undefined | {
7
47
  year?: number;
8
48
  month?: Month;
9
49
  valueAsDate: false | undefined;
10
50
  }): ColombianHoliday[];
11
- export declare function colombianHolidays(options?: {
51
+ declare function colombianHolidays(options?: {
12
52
  year?: number;
13
53
  month?: Month;
14
54
  valueAsDate: true;
15
55
  }): ColombianHolidayWithNativeDate[];
16
- export declare function colombianHolidays(options?: {
56
+ declare function colombianHolidays(options?: {
17
57
  year?: number;
18
58
  month?: Month;
19
59
  valueAsDate?: boolean;
20
60
  }): ColombianHoliday[] | ColombianHolidayWithNativeDate[];
21
- export default colombianHolidays;
22
- export { getHolidaysForYear } from "./utils/getHolidaysByYear";
23
- export { isHoliday } from "./utils/isHoliday";
24
- export { holidaysWithinInterval } from "./utils/holidaysWithinInterval";
61
+
62
+ export { FIRST_HOLIDAY_YEAR, LAST_HOLIDAY_YEAR, type Month, colombianHolidays, colombianHolidays as default, getHolidaysForYear, holidaysWithinInterval, isHoliday };
package/dist/index.js CHANGED
@@ -1,47 +1,337 @@
1
1
  "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
2
+ var __create = Object.create;
3
+ var __defProp = Object.defineProperty;
4
+ var __getOwnPropDesc = Object.getOwnPropertyDescriptor;
5
+ var __getOwnPropNames = Object.getOwnPropertyNames;
6
+ var __getProtoOf = Object.getPrototypeOf;
7
+ var __hasOwnProp = Object.prototype.hasOwnProperty;
8
+ var __export = (target, all) => {
9
+ for (var name in all)
10
+ __defProp(target, name, { get: all[name], enumerable: true });
4
11
  };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.holidaysWithinInterval = exports.isHoliday = exports.getHolidaysForYear = exports.colombianHolidays = exports.LAST_HOLIDAY_YEAR = exports.FIRST_HOLIDAY_YEAR = void 0;
7
- const helpers_1 = __importDefault(require("./helpers"));
8
- const holidays_1 = __importDefault(require("./holidays"));
9
- // pascua package year limits
10
- exports.FIRST_HOLIDAY_YEAR = 1583;
11
- exports.LAST_HOLIDAY_YEAR = 4099;
12
- function colombianHolidays({ year = new Date().getUTCFullYear(), month, valueAsDate = false, } = {}) {
13
- if (year < exports.FIRST_HOLIDAY_YEAR || year > exports.LAST_HOLIDAY_YEAR) {
14
- throw new Error(`The year should be between ${exports.FIRST_HOLIDAY_YEAR} and ${exports.LAST_HOLIDAY_YEAR}`);
12
+ var __copyProps = (to, from, except, desc) => {
13
+ if (from && typeof from === "object" || typeof from === "function") {
14
+ for (let key of __getOwnPropNames(from))
15
+ if (!__hasOwnProp.call(to, key) && key !== except)
16
+ __defProp(to, key, { get: () => from[key], enumerable: !(desc = __getOwnPropDesc(from, key)) || desc.enumerable });
17
+ }
18
+ return to;
19
+ };
20
+ var __toESM = (mod, isNodeMode, target) => (target = mod != null ? __create(__getProtoOf(mod)) : {}, __copyProps(
21
+ // If the importer is in node compatibility mode or this is not an ESM
22
+ // file that has been converted to a CommonJS file using a Babel-
23
+ // compatible transform (i.e. "__esModule" has not been set), then set
24
+ // "default" to the CommonJS "module.exports" for node compatibility.
25
+ isNodeMode || !mod || !mod.__esModule ? __defProp(target, "default", { value: mod, enumerable: true }) : target,
26
+ mod
27
+ ));
28
+ var __toCommonJS = (mod) => __copyProps(__defProp({}, "__esModule", { value: true }), mod);
29
+
30
+ // src/index.ts
31
+ var index_exports = {};
32
+ __export(index_exports, {
33
+ FIRST_HOLIDAY_YEAR: () => FIRST_HOLIDAY_YEAR,
34
+ LAST_HOLIDAY_YEAR: () => LAST_HOLIDAY_YEAR,
35
+ colombianHolidays: () => colombianHolidays,
36
+ default: () => index_default,
37
+ getHolidaysForYear: () => getHolidaysForYear,
38
+ holidaysWithinInterval: () => holidaysWithinInterval,
39
+ isHoliday: () => isHoliday
40
+ });
41
+ module.exports = __toCommonJS(index_exports);
42
+
43
+ // src/helpers.ts
44
+ var import_pascua = __toESM(require("pascua"));
45
+ var NEW_HOLIDAY_SCHEMA_START_YEAR = 1984;
46
+ function getNextDayOfWeek(date, dayOfWeek) {
47
+ const resultDate = new Date(date);
48
+ resultDate.setUTCDate(
49
+ date.getUTCDate() + (7 + dayOfWeek - date.getUTCDay()) % 7
50
+ );
51
+ return resultDate;
52
+ }
53
+ function getNextMonday(date) {
54
+ const MONDAY = 1;
55
+ return getNextDayOfWeek(date, MONDAY);
56
+ }
57
+ function isEasterHoliday(holiday) {
58
+ return "offset" in holiday;
59
+ }
60
+ function getHolidayDate(holiday, year) {
61
+ if (isEasterHoliday(holiday)) {
62
+ const { month, day } = (0, import_pascua.default)(year);
63
+ const date = new Date(generateUtcStringFromDateParts(year, month, 1));
64
+ date.setUTCDate(day + holiday.offset);
65
+ return date;
66
+ }
67
+ return new Date(
68
+ generateUtcStringFromDateParts(year, holiday.month, holiday.day)
69
+ );
70
+ }
71
+ function generateUtcStringFromDateParts(year, month, day) {
72
+ return `${year}-${String(month).padStart(2, "0")}-${String(day).padStart(
73
+ 2,
74
+ "0"
75
+ )}`;
76
+ }
77
+ function getHoliday(holiday, {
78
+ year = (/* @__PURE__ */ new Date()).getUTCFullYear(),
79
+ valueAsDate = false
80
+ } = {}) {
81
+ const holidayDate = getHolidayDate(holiday, year);
82
+ const celebrationDate = year >= NEW_HOLIDAY_SCHEMA_START_YEAR && holiday.nextMonday ? getNextMonday(holidayDate) : holidayDate;
83
+ return {
84
+ date: valueAsDate ? holidayDate : holidayDate.toISOString().slice(0, 10),
85
+ celebrationDate: valueAsDate ? celebrationDate : celebrationDate.toISOString().slice(0, 10),
86
+ name: holiday.name,
87
+ nextMonday: year >= NEW_HOLIDAY_SCHEMA_START_YEAR && holiday.nextMonday
88
+ };
89
+ }
90
+ var helpers_default = getHoliday;
91
+
92
+ // src/holidays.ts
93
+ var dateHolidays = [
94
+ {
95
+ month: 1,
96
+ day: 1,
97
+ name: {
98
+ es: "A\xF1o Nuevo",
99
+ en: "New Year's Day"
100
+ },
101
+ nextMonday: false
102
+ },
103
+ {
104
+ month: 1,
105
+ day: 6,
106
+ name: {
107
+ es: "Reyes Magos",
108
+ en: "Epiphany"
109
+ },
110
+ nextMonday: true
111
+ },
112
+ {
113
+ month: 3,
114
+ day: 19,
115
+ name: {
116
+ es: "San Jos\xE9",
117
+ en: "Saint Joseph's Day"
118
+ },
119
+ nextMonday: true
120
+ },
121
+ {
122
+ month: 5,
123
+ day: 1,
124
+ name: {
125
+ es: "D\xEDa del Trabajo",
126
+ en: "Labour Day"
127
+ },
128
+ nextMonday: false
129
+ },
130
+ {
131
+ month: 6,
132
+ day: 29,
133
+ name: {
134
+ es: "San Pedro y San Pablo",
135
+ en: "Saint Peter and Saint Paul"
136
+ },
137
+ nextMonday: true
138
+ },
139
+ {
140
+ month: 7,
141
+ day: 20,
142
+ name: {
143
+ es: "Grito de la Independencia",
144
+ en: "Declaration of Independence"
145
+ },
146
+ nextMonday: false
147
+ },
148
+ {
149
+ month: 8,
150
+ day: 7,
151
+ name: {
152
+ es: "Batalla de Boyac\xE1",
153
+ en: "Battle of Boyac\xE1"
154
+ },
155
+ nextMonday: false
156
+ },
157
+ {
158
+ month: 8,
159
+ day: 15,
160
+ name: {
161
+ es: "Asunci\xF3n de la Virgen",
162
+ en: "Assumption of Mary"
163
+ },
164
+ nextMonday: true
165
+ },
166
+ {
167
+ month: 10,
168
+ day: 12,
169
+ name: {
170
+ es: "D\xEDa de la Raza",
171
+ en: "Columbus Day"
172
+ },
173
+ nextMonday: true
174
+ },
175
+ {
176
+ month: 11,
177
+ day: 1,
178
+ name: {
179
+ es: "Todos los Santos",
180
+ en: "All Saints\u2019 Day"
181
+ },
182
+ nextMonday: true
183
+ },
184
+ {
185
+ month: 11,
186
+ day: 11,
187
+ name: { es: "Independencia de Cartagena", en: "Independence of Cartagena" },
188
+ nextMonday: true
189
+ },
190
+ {
191
+ month: 12,
192
+ day: 8,
193
+ name: { es: "Inmaculada Concepci\xF3n", en: "Immaculate Conception" },
194
+ nextMonday: false
195
+ },
196
+ {
197
+ month: 12,
198
+ day: 25,
199
+ name: { es: "Navidad", en: "Christmas" },
200
+ nextMonday: false
201
+ }
202
+ ];
203
+ var easterHolidays = [
204
+ {
205
+ offset: -3,
206
+ name: { es: "Jueves Santo", en: "Maundy Thursday" },
207
+ nextMonday: false
208
+ },
209
+ {
210
+ offset: -2,
211
+ name: { es: "Viernes Santo", en: "Good Friday" },
212
+ nextMonday: false
213
+ },
214
+ {
215
+ offset: 39,
216
+ name: { es: "Ascensi\xF3n del Se\xF1or", en: "Ascension of Jesus" },
217
+ nextMonday: true
218
+ },
219
+ {
220
+ offset: 60,
221
+ name: { es: "Corpus Christi", en: "Corpus Christi" },
222
+ nextMonday: true
223
+ },
224
+ {
225
+ offset: 68,
226
+ name: { es: "Sagrado Coraz\xF3n de Jes\xFAs", en: "Sacred Heart" },
227
+ nextMonday: true
228
+ }
229
+ ];
230
+ var holidays_default = [...dateHolidays, ...easterHolidays];
231
+
232
+ // src/utils/getHolidaysByYear.ts
233
+ var holidaysWithNativeDateCache = /* @__PURE__ */ new Map();
234
+ var holidaysCache = /* @__PURE__ */ new Map();
235
+ function getHolidaysForYear(year, { valueAsDate = false } = {}) {
236
+ if (valueAsDate) {
237
+ const cachedHolidays2 = holidaysWithNativeDateCache.get(year);
238
+ if (cachedHolidays2) {
239
+ return cachedHolidays2;
240
+ }
241
+ const holidays2 = index_default({ year, valueAsDate });
242
+ holidaysWithNativeDateCache.set(year, holidays2);
243
+ return holidays2;
244
+ }
245
+ const cachedHolidays = holidaysCache.get(year);
246
+ if (cachedHolidays) {
247
+ return cachedHolidays;
248
+ }
249
+ const holidays = index_default({ year, valueAsDate });
250
+ holidaysCache.set(year, holidays);
251
+ return holidays;
252
+ }
253
+
254
+ // src/utils/helpers.ts
255
+ function isSameDate(date1, date2) {
256
+ return date1.getUTCDate() === date2.getUTCDate() && date1.getUTCMonth() === date2.getUTCMonth() && date1.getUTCFullYear() === date2.getUTCFullYear();
257
+ }
258
+
259
+ // src/utils/isHoliday.ts
260
+ function isHoliday(date) {
261
+ const holidays = getHolidaysForYear(date.getUTCFullYear(), {
262
+ valueAsDate: true
263
+ });
264
+ return holidays.some(
265
+ ({ celebrationDate }) => isSameDate(celebrationDate, date)
266
+ );
267
+ }
268
+
269
+ // src/utils/holidaysWithinInterval.ts
270
+ function holidaysWithinInterval({
271
+ start,
272
+ end,
273
+ valueAsDate = false
274
+ }) {
275
+ if (start >= end) {
276
+ throw new Error("end date should be greater than start date");
277
+ }
278
+ const yearEnd = end.getUTCFullYear();
279
+ const yearStart = start.getUTCFullYear();
280
+ const holidays = Array.from(
281
+ { length: yearEnd - yearStart + 1 },
282
+ (_, i) => getHolidaysForYear(i + yearStart, { valueAsDate: true })
283
+ ).flat();
284
+ const holidaysWithin = holidays.filter(
285
+ ({ celebrationDate }) => celebrationDate >= start && celebrationDate <= end
286
+ );
287
+ if (valueAsDate) {
288
+ return holidaysWithin;
289
+ }
290
+ return holidaysWithin.map((holiday) => ({
291
+ ...holiday,
292
+ date: holiday.date.toISOString().slice(0, 10),
293
+ celebrationDate: holiday.celebrationDate.toISOString().slice(0, 10)
294
+ }));
295
+ }
296
+
297
+ // src/index.ts
298
+ var FIRST_HOLIDAY_YEAR = 1583;
299
+ var LAST_HOLIDAY_YEAR = 4099;
300
+ function colombianHolidays({
301
+ year = (/* @__PURE__ */ new Date()).getUTCFullYear(),
302
+ month,
303
+ valueAsDate = false
304
+ } = {}) {
305
+ if (year < FIRST_HOLIDAY_YEAR || year > LAST_HOLIDAY_YEAR) {
306
+ throw new Error(
307
+ `The year should be between ${FIRST_HOLIDAY_YEAR} and ${LAST_HOLIDAY_YEAR}`
308
+ );
309
+ }
310
+ return holidays_default.map((holiday) => helpers_default(holiday, { year, valueAsDate })).filter((holiday) => {
311
+ if (month === void 0) {
312
+ return true;
15
313
  }
16
- return holidays_1.default
17
- .map((holiday) => (0, helpers_1.default)(holiday, { year, valueAsDate }))
18
- .filter((holiday) => {
19
- if (month === undefined) {
20
- return true;
21
- }
22
- if (typeof holiday.celebrationDate === "string") {
23
- return Number(holiday.celebrationDate.slice(5, 7)) === month;
24
- }
25
- return holiday.celebrationDate.getUTCMonth() + 1 === month;
26
- })
27
- .sort((a, b) => {
28
- if (a.celebrationDate instanceof Date &&
29
- b.celebrationDate instanceof Date) {
30
- return a.celebrationDate.getTime() - b.celebrationDate.getTime();
31
- }
32
- if (typeof a.celebrationDate === "string" &&
33
- typeof b.celebrationDate === "string") {
34
- return a.celebrationDate.localeCompare(b.celebrationDate);
35
- }
36
- throw new Error("Invariant violation: this state is not possible.");
37
- });
38
- }
39
- exports.colombianHolidays = colombianHolidays;
40
- exports.default = colombianHolidays;
41
- var getHolidaysByYear_1 = require("./utils/getHolidaysByYear");
42
- Object.defineProperty(exports, "getHolidaysForYear", { enumerable: true, get: function () { return getHolidaysByYear_1.getHolidaysForYear; } });
43
- var isHoliday_1 = require("./utils/isHoliday");
44
- Object.defineProperty(exports, "isHoliday", { enumerable: true, get: function () { return isHoliday_1.isHoliday; } });
45
- var holidaysWithinInterval_1 = require("./utils/holidaysWithinInterval");
46
- Object.defineProperty(exports, "holidaysWithinInterval", { enumerable: true, get: function () { return holidaysWithinInterval_1.holidaysWithinInterval; } });
47
- //# sourceMappingURL=index.js.map
314
+ if (typeof holiday.celebrationDate === "string") {
315
+ return Number(holiday.celebrationDate.slice(5, 7)) === month;
316
+ }
317
+ return holiday.celebrationDate.getUTCMonth() + 1 === month;
318
+ }).sort((a, b) => {
319
+ if (a.celebrationDate instanceof Date && b.celebrationDate instanceof Date) {
320
+ return a.celebrationDate.getTime() - b.celebrationDate.getTime();
321
+ }
322
+ if (typeof a.celebrationDate === "string" && typeof b.celebrationDate === "string") {
323
+ return a.celebrationDate.localeCompare(b.celebrationDate);
324
+ }
325
+ throw new Error("Invariant violation: this state is not possible.");
326
+ });
327
+ }
328
+ var index_default = colombianHolidays;
329
+ // Annotate the CommonJS export names for ESM import in node:
330
+ 0 && (module.exports = {
331
+ FIRST_HOLIDAY_YEAR,
332
+ LAST_HOLIDAY_YEAR,
333
+ colombianHolidays,
334
+ getHolidaysForYear,
335
+ holidaysWithinInterval,
336
+ isHoliday
337
+ });
package/dist/index.mjs ADDED
@@ -0,0 +1,295 @@
1
+ // src/helpers.ts
2
+ import pascua from "pascua";
3
+ var NEW_HOLIDAY_SCHEMA_START_YEAR = 1984;
4
+ function getNextDayOfWeek(date, dayOfWeek) {
5
+ const resultDate = new Date(date);
6
+ resultDate.setUTCDate(
7
+ date.getUTCDate() + (7 + dayOfWeek - date.getUTCDay()) % 7
8
+ );
9
+ return resultDate;
10
+ }
11
+ function getNextMonday(date) {
12
+ const MONDAY = 1;
13
+ return getNextDayOfWeek(date, MONDAY);
14
+ }
15
+ function isEasterHoliday(holiday) {
16
+ return "offset" in holiday;
17
+ }
18
+ function getHolidayDate(holiday, year) {
19
+ if (isEasterHoliday(holiday)) {
20
+ const { month, day } = pascua(year);
21
+ const date = new Date(generateUtcStringFromDateParts(year, month, 1));
22
+ date.setUTCDate(day + holiday.offset);
23
+ return date;
24
+ }
25
+ return new Date(
26
+ generateUtcStringFromDateParts(year, holiday.month, holiday.day)
27
+ );
28
+ }
29
+ function generateUtcStringFromDateParts(year, month, day) {
30
+ return `${year}-${String(month).padStart(2, "0")}-${String(day).padStart(
31
+ 2,
32
+ "0"
33
+ )}`;
34
+ }
35
+ function getHoliday(holiday, {
36
+ year = (/* @__PURE__ */ new Date()).getUTCFullYear(),
37
+ valueAsDate = false
38
+ } = {}) {
39
+ const holidayDate = getHolidayDate(holiday, year);
40
+ const celebrationDate = year >= NEW_HOLIDAY_SCHEMA_START_YEAR && holiday.nextMonday ? getNextMonday(holidayDate) : holidayDate;
41
+ return {
42
+ date: valueAsDate ? holidayDate : holidayDate.toISOString().slice(0, 10),
43
+ celebrationDate: valueAsDate ? celebrationDate : celebrationDate.toISOString().slice(0, 10),
44
+ name: holiday.name,
45
+ nextMonday: year >= NEW_HOLIDAY_SCHEMA_START_YEAR && holiday.nextMonday
46
+ };
47
+ }
48
+ var helpers_default = getHoliday;
49
+
50
+ // src/holidays.ts
51
+ var dateHolidays = [
52
+ {
53
+ month: 1,
54
+ day: 1,
55
+ name: {
56
+ es: "A\xF1o Nuevo",
57
+ en: "New Year's Day"
58
+ },
59
+ nextMonday: false
60
+ },
61
+ {
62
+ month: 1,
63
+ day: 6,
64
+ name: {
65
+ es: "Reyes Magos",
66
+ en: "Epiphany"
67
+ },
68
+ nextMonday: true
69
+ },
70
+ {
71
+ month: 3,
72
+ day: 19,
73
+ name: {
74
+ es: "San Jos\xE9",
75
+ en: "Saint Joseph's Day"
76
+ },
77
+ nextMonday: true
78
+ },
79
+ {
80
+ month: 5,
81
+ day: 1,
82
+ name: {
83
+ es: "D\xEDa del Trabajo",
84
+ en: "Labour Day"
85
+ },
86
+ nextMonday: false
87
+ },
88
+ {
89
+ month: 6,
90
+ day: 29,
91
+ name: {
92
+ es: "San Pedro y San Pablo",
93
+ en: "Saint Peter and Saint Paul"
94
+ },
95
+ nextMonday: true
96
+ },
97
+ {
98
+ month: 7,
99
+ day: 20,
100
+ name: {
101
+ es: "Grito de la Independencia",
102
+ en: "Declaration of Independence"
103
+ },
104
+ nextMonday: false
105
+ },
106
+ {
107
+ month: 8,
108
+ day: 7,
109
+ name: {
110
+ es: "Batalla de Boyac\xE1",
111
+ en: "Battle of Boyac\xE1"
112
+ },
113
+ nextMonday: false
114
+ },
115
+ {
116
+ month: 8,
117
+ day: 15,
118
+ name: {
119
+ es: "Asunci\xF3n de la Virgen",
120
+ en: "Assumption of Mary"
121
+ },
122
+ nextMonday: true
123
+ },
124
+ {
125
+ month: 10,
126
+ day: 12,
127
+ name: {
128
+ es: "D\xEDa de la Raza",
129
+ en: "Columbus Day"
130
+ },
131
+ nextMonday: true
132
+ },
133
+ {
134
+ month: 11,
135
+ day: 1,
136
+ name: {
137
+ es: "Todos los Santos",
138
+ en: "All Saints\u2019 Day"
139
+ },
140
+ nextMonday: true
141
+ },
142
+ {
143
+ month: 11,
144
+ day: 11,
145
+ name: { es: "Independencia de Cartagena", en: "Independence of Cartagena" },
146
+ nextMonday: true
147
+ },
148
+ {
149
+ month: 12,
150
+ day: 8,
151
+ name: { es: "Inmaculada Concepci\xF3n", en: "Immaculate Conception" },
152
+ nextMonday: false
153
+ },
154
+ {
155
+ month: 12,
156
+ day: 25,
157
+ name: { es: "Navidad", en: "Christmas" },
158
+ nextMonday: false
159
+ }
160
+ ];
161
+ var easterHolidays = [
162
+ {
163
+ offset: -3,
164
+ name: { es: "Jueves Santo", en: "Maundy Thursday" },
165
+ nextMonday: false
166
+ },
167
+ {
168
+ offset: -2,
169
+ name: { es: "Viernes Santo", en: "Good Friday" },
170
+ nextMonday: false
171
+ },
172
+ {
173
+ offset: 39,
174
+ name: { es: "Ascensi\xF3n del Se\xF1or", en: "Ascension of Jesus" },
175
+ nextMonday: true
176
+ },
177
+ {
178
+ offset: 60,
179
+ name: { es: "Corpus Christi", en: "Corpus Christi" },
180
+ nextMonday: true
181
+ },
182
+ {
183
+ offset: 68,
184
+ name: { es: "Sagrado Coraz\xF3n de Jes\xFAs", en: "Sacred Heart" },
185
+ nextMonday: true
186
+ }
187
+ ];
188
+ var holidays_default = [...dateHolidays, ...easterHolidays];
189
+
190
+ // src/utils/getHolidaysByYear.ts
191
+ var holidaysWithNativeDateCache = /* @__PURE__ */ new Map();
192
+ var holidaysCache = /* @__PURE__ */ new Map();
193
+ function getHolidaysForYear(year, { valueAsDate = false } = {}) {
194
+ if (valueAsDate) {
195
+ const cachedHolidays2 = holidaysWithNativeDateCache.get(year);
196
+ if (cachedHolidays2) {
197
+ return cachedHolidays2;
198
+ }
199
+ const holidays2 = index_default({ year, valueAsDate });
200
+ holidaysWithNativeDateCache.set(year, holidays2);
201
+ return holidays2;
202
+ }
203
+ const cachedHolidays = holidaysCache.get(year);
204
+ if (cachedHolidays) {
205
+ return cachedHolidays;
206
+ }
207
+ const holidays = index_default({ year, valueAsDate });
208
+ holidaysCache.set(year, holidays);
209
+ return holidays;
210
+ }
211
+
212
+ // src/utils/helpers.ts
213
+ function isSameDate(date1, date2) {
214
+ return date1.getUTCDate() === date2.getUTCDate() && date1.getUTCMonth() === date2.getUTCMonth() && date1.getUTCFullYear() === date2.getUTCFullYear();
215
+ }
216
+
217
+ // src/utils/isHoliday.ts
218
+ function isHoliday(date) {
219
+ const holidays = getHolidaysForYear(date.getUTCFullYear(), {
220
+ valueAsDate: true
221
+ });
222
+ return holidays.some(
223
+ ({ celebrationDate }) => isSameDate(celebrationDate, date)
224
+ );
225
+ }
226
+
227
+ // src/utils/holidaysWithinInterval.ts
228
+ function holidaysWithinInterval({
229
+ start,
230
+ end,
231
+ valueAsDate = false
232
+ }) {
233
+ if (start >= end) {
234
+ throw new Error("end date should be greater than start date");
235
+ }
236
+ const yearEnd = end.getUTCFullYear();
237
+ const yearStart = start.getUTCFullYear();
238
+ const holidays = Array.from(
239
+ { length: yearEnd - yearStart + 1 },
240
+ (_, i) => getHolidaysForYear(i + yearStart, { valueAsDate: true })
241
+ ).flat();
242
+ const holidaysWithin = holidays.filter(
243
+ ({ celebrationDate }) => celebrationDate >= start && celebrationDate <= end
244
+ );
245
+ if (valueAsDate) {
246
+ return holidaysWithin;
247
+ }
248
+ return holidaysWithin.map((holiday) => ({
249
+ ...holiday,
250
+ date: holiday.date.toISOString().slice(0, 10),
251
+ celebrationDate: holiday.celebrationDate.toISOString().slice(0, 10)
252
+ }));
253
+ }
254
+
255
+ // src/index.ts
256
+ var FIRST_HOLIDAY_YEAR = 1583;
257
+ var LAST_HOLIDAY_YEAR = 4099;
258
+ function colombianHolidays({
259
+ year = (/* @__PURE__ */ new Date()).getUTCFullYear(),
260
+ month,
261
+ valueAsDate = false
262
+ } = {}) {
263
+ if (year < FIRST_HOLIDAY_YEAR || year > LAST_HOLIDAY_YEAR) {
264
+ throw new Error(
265
+ `The year should be between ${FIRST_HOLIDAY_YEAR} and ${LAST_HOLIDAY_YEAR}`
266
+ );
267
+ }
268
+ return holidays_default.map((holiday) => helpers_default(holiday, { year, valueAsDate })).filter((holiday) => {
269
+ if (month === void 0) {
270
+ return true;
271
+ }
272
+ if (typeof holiday.celebrationDate === "string") {
273
+ return Number(holiday.celebrationDate.slice(5, 7)) === month;
274
+ }
275
+ return holiday.celebrationDate.getUTCMonth() + 1 === month;
276
+ }).sort((a, b) => {
277
+ if (a.celebrationDate instanceof Date && b.celebrationDate instanceof Date) {
278
+ return a.celebrationDate.getTime() - b.celebrationDate.getTime();
279
+ }
280
+ if (typeof a.celebrationDate === "string" && typeof b.celebrationDate === "string") {
281
+ return a.celebrationDate.localeCompare(b.celebrationDate);
282
+ }
283
+ throw new Error("Invariant violation: this state is not possible.");
284
+ });
285
+ }
286
+ var index_default = colombianHolidays;
287
+ export {
288
+ FIRST_HOLIDAY_YEAR,
289
+ LAST_HOLIDAY_YEAR,
290
+ colombianHolidays,
291
+ index_default as default,
292
+ getHolidaysForYear,
293
+ holidaysWithinInterval,
294
+ isHoliday
295
+ };
package/package.json CHANGED
@@ -1,15 +1,17 @@
1
1
  {
2
2
  "name": "colombian-holidays",
3
- "version": "5.0.3",
3
+ "version": "5.0.5",
4
4
  "description": "Colombian holidays",
5
5
  "main": "dist/index.js",
6
6
  "scripts": {
7
7
  "format": "prettier --write .",
8
8
  "lint": "eslint . --ext .ts --fix",
9
- "test": "jest --coverage",
10
- "build": "tsc",
11
- "prepublishOnly": "tsc",
12
- "ts-node": "ts-node"
9
+ "test": "vitest run",
10
+ "build": "tsup src/index.ts --dts --format cjs,esm --out-dir dist",
11
+ "build:cjs": "tsup src/index.ts --format cjs --out-dir dist/cjs",
12
+ "build:esm": "tsup src/index.ts --format esm --out-dir dist/esm",
13
+ "build:types": "tsup src/index.ts --dts-only --out-dir dist/types",
14
+ "prepublishOnly": "npm run build"
13
15
  },
14
16
  "license": "MIT",
15
17
  "bugs": {
@@ -25,19 +27,16 @@
25
27
  "Holidays"
26
28
  ],
27
29
  "devDependencies": {
28
- "@types/jest": "^27.4.1",
29
- "@typescript-eslint/eslint-plugin": "^5.21.0",
30
- "@typescript-eslint/parser": "^5.21.0",
31
- "eslint": "^8.14.0",
32
- "jest": "^27.0.1",
33
- "prettier": "^2.6.2",
34
- "timezone-mock": "^1.3.1",
35
- "ts-jest": "^27.1.4",
36
- "ts-node": "^10.9.1",
37
- "typescript": "^4.6.4"
30
+ "@eslint/js": "^9.32.0",
31
+ "eslint": "^9.32.0",
32
+ "prettier": "^3.6.2",
33
+ "tsup": "^8.5.0",
34
+ "typescript": "^5.8.3",
35
+ "typescript-eslint": "^8.38.0",
36
+ "vitest": "^3.2.4"
38
37
  },
39
38
  "dependencies": {
40
- "pascua": "^2.1.5"
39
+ "pascua": "^2.1.8"
41
40
  },
42
41
  "files": [
43
42
  "dist"
package/dist/helpers.d.ts DELETED
@@ -1,15 +0,0 @@
1
- import type { Holiday, ColombianHoliday, ColombianHolidayWithNativeDate } from "./types";
2
- export declare const NEW_HOLIDAY_SCHEMA_START_YEAR = 1984;
3
- declare function getHoliday(holiday: Holiday, options?: {
4
- year?: number;
5
- valueAsDate: false | undefined;
6
- }): ColombianHoliday;
7
- declare function getHoliday(holiday: Holiday, options: {
8
- year?: number;
9
- valueAsDate: true;
10
- }): ColombianHolidayWithNativeDate;
11
- declare function getHoliday(holiday: Holiday, options?: {
12
- year?: number;
13
- valueAsDate?: boolean;
14
- }): ColombianHoliday | ColombianHolidayWithNativeDate;
15
- export default getHoliday;
package/dist/helpers.js DELETED
@@ -1,50 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.NEW_HOLIDAY_SCHEMA_START_YEAR = void 0;
7
- const pascua_1 = __importDefault(require("pascua"));
8
- // 1984 is the year when the current holidays scheme is enforced
9
- // http://www.alcaldiabogota.gov.co/sisjur/normas/Norma1.jsp?i=4954
10
- exports.NEW_HOLIDAY_SCHEMA_START_YEAR = 1984;
11
- function getNextDayOfWeek(date, dayOfWeek) {
12
- const resultDate = new Date(date);
13
- resultDate.setUTCDate(date.getUTCDate() + ((7 + dayOfWeek - date.getUTCDay()) % 7));
14
- return resultDate;
15
- }
16
- function getNextMonday(date) {
17
- const MONDAY = 1;
18
- return getNextDayOfWeek(date, MONDAY);
19
- }
20
- function isEasterHoliday(holiday) {
21
- return "offset" in holiday;
22
- }
23
- function getHolidayDate(holiday, year) {
24
- if (isEasterHoliday(holiday)) {
25
- const { month, day } = (0, pascua_1.default)(year);
26
- const date = new Date(generateUtcStringFromDateParts(year, month, 1));
27
- date.setUTCDate(day + holiday.offset);
28
- return date;
29
- }
30
- return new Date(generateUtcStringFromDateParts(year, holiday.month, holiday.day));
31
- }
32
- function generateUtcStringFromDateParts(year, month, day) {
33
- return `${year}-${String(month).padStart(2, "0")}-${String(day).padStart(2, "0")}`;
34
- }
35
- function getHoliday(holiday, { year = new Date().getUTCFullYear(), valueAsDate = false, } = {}) {
36
- const holidayDate = getHolidayDate(holiday, year);
37
- const celebrationDate = year >= exports.NEW_HOLIDAY_SCHEMA_START_YEAR && holiday.nextMonday
38
- ? getNextMonday(holidayDate)
39
- : holidayDate;
40
- return {
41
- date: valueAsDate ? holidayDate : holidayDate.toISOString().slice(0, 10),
42
- celebrationDate: valueAsDate
43
- ? celebrationDate
44
- : celebrationDate.toISOString().slice(0, 10),
45
- name: holiday.name,
46
- nextMonday: year >= exports.NEW_HOLIDAY_SCHEMA_START_YEAR && holiday.nextMonday,
47
- };
48
- }
49
- exports.default = getHoliday;
50
- //# sourceMappingURL=helpers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../src/helpers.ts"],"names":[],"mappings":";;;;;;AAAA,oDAA4B;AAQ5B,gEAAgE;AAChE,mEAAmE;AACtD,QAAA,6BAA6B,GAAG,IAAI,CAAC;AAElD,SAAS,gBAAgB,CAAC,IAAU,EAAE,SAAiB;IACrD,MAAM,UAAU,GAAG,IAAI,IAAI,CAAC,IAAI,CAAC,CAAC;IAClC,UAAU,CAAC,UAAU,CACnB,IAAI,CAAC,UAAU,EAAE,GAAG,CAAC,CAAC,CAAC,GAAG,SAAS,GAAG,IAAI,CAAC,SAAS,EAAE,CAAC,GAAG,CAAC,CAAC,CAC7D,CAAC;IACF,OAAO,UAAU,CAAC;AACpB,CAAC;AAED,SAAS,aAAa,CAAC,IAAU;IAC/B,MAAM,MAAM,GAAG,CAAC,CAAC;IACjB,OAAO,gBAAgB,CAAC,IAAI,EAAE,MAAM,CAAC,CAAC;AACxC,CAAC;AAED,SAAS,eAAe,CAAC,OAAgB;IACvC,OAAO,QAAQ,IAAI,OAAO,CAAC;AAC7B,CAAC;AAED,SAAS,cAAc,CAAC,OAAgB,EAAE,IAAY;IACpD,IAAI,eAAe,CAAC,OAAO,CAAC,EAAE;QAC5B,MAAM,EAAE,KAAK,EAAE,GAAG,EAAE,GAAG,IAAA,gBAAM,EAAC,IAAI,CAAC,CAAC;QACpC,MAAM,IAAI,GAAG,IAAI,IAAI,CAAC,8BAA8B,CAAC,IAAI,EAAE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AC;AACJ,CAAC;AAED,kBAAe,UAAU,CAAC"}
@@ -1,3 +0,0 @@
1
- import type { DateHoliday, EasterHoliday } from "./types";
2
- declare const _default: (DateHoliday | EasterHoliday)[];
3
- export default _default;
package/dist/holidays.js DELETED
@@ -1,147 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- const dateHolidays = [
4
- {
5
- month: 1,
6
- day: 1,
7
- name: {
8
- es: "Año Nuevo",
9
- en: "New Year's Day",
10
- },
11
- nextMonday: false,
12
- },
13
- {
14
- month: 1,
15
- day: 6,
16
- name: {
17
- es: "Reyes Magos",
18
- en: "Epiphany",
19
- },
20
- nextMonday: true,
21
- },
22
- {
23
- month: 3,
24
- day: 19,
25
- name: {
26
- es: "San José",
27
- en: "Saint Joseph's Day",
28
- },
29
- nextMonday: true,
30
- },
31
- {
32
- month: 5,
33
- day: 1,
34
- name: {
35
- es: "Día del Trabajo",
36
- en: "Labour Day",
37
- },
38
- nextMonday: false,
39
- },
40
- {
41
- month: 6,
42
- day: 29,
43
- name: {
44
- es: "San Pedro y San Pablo",
45
- en: "Saint Peter and Saint Paul",
46
- },
47
- nextMonday: true,
48
- },
49
- {
50
- month: 7,
51
- day: 20,
52
- name: {
53
- es: "Grito de la Independencia",
54
- en: "Declaration of Independence",
55
- },
56
- nextMonday: false,
57
- },
58
- {
59
- month: 8,
60
- day: 7,
61
- name: {
62
- es: "Batalla de Boyacá",
63
- en: "Battle of Boyacá",
64
- },
65
- nextMonday: false,
66
- },
67
- {
68
- month: 8,
69
- day: 15,
70
- name: {
71
- es: "Asunción de la Virgen",
72
- en: "Assumption of Mary",
73
- },
74
- nextMonday: true,
75
- },
76
- {
77
- month: 10,
78
- day: 12,
79
- name: {
80
- es: "Día de la Raza",
81
- en: "Columbus Day",
82
- },
83
- nextMonday: true,
84
- },
85
- {
86
- month: 11,
87
- day: 1,
88
- name: {
89
- es: "Todos los Santos",
90
- en: "All Saints’ Day",
91
- },
92
- nextMonday: true,
93
- },
94
- {
95
- month: 11,
96
- day: 11,
97
- name: { es: "Independencia de Cartagena", en: "Independence of Cartagena" },
98
- nextMonday: true,
99
- },
100
- {
101
- month: 12,
102
- day: 8,
103
- name: { es: "Inmaculada Concepción", en: "Immaculate Conception" },
104
- nextMonday: false,
105
- },
106
- {
107
- month: 12,
108
- day: 25,
109
- name: { es: "Navidad", en: "Christmas" },
110
- nextMonday: false,
111
- },
112
- ];
113
- // We could simplify the calculation by setting the offset to match Monday.
114
- // For example, the date for the 'Corpus Christi' is 60 days after Easter
115
- // and that's the date it is celebrated in most countries. In Colombia,
116
- // that date is moved to the next monday, hence, we use 60 for the offset
117
- // and then get the next monday instead of directly using 64 as the offset.
118
- // https://www.alcaldiabogota.gov.co/sisjur/normas/Norma1.jsp?i=4954
119
- const easterHolidays = [
120
- {
121
- offset: -3,
122
- name: { es: "Jueves Santo", en: "Maundy Thursday" },
123
- nextMonday: false,
124
- },
125
- {
126
- offset: -2,
127
- name: { es: "Viernes Santo", en: "Good Friday" },
128
- nextMonday: false,
129
- },
130
- {
131
- offset: 39,
132
- name: { es: "Ascensión del Señor", en: "Ascension of Jesus" },
133
- nextMonday: true,
134
- },
135
- {
136
- offset: 60,
137
- name: { es: "Corpus Christi", en: "Corpus Christi" },
138
- nextMonday: true,
139
- },
140
- {
141
- offset: 68,
142
- name: { es: "Sagrado Corazón de Jesús", en: "Sacred Heart" },
143
- nextMonday: true,
144
- },
145
- ];
146
- exports.default = [...dateHolidays, ...easterHolidays];
147
- //# sourceMappingURL=holidays.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"holidays.js","sourceRoot":"","sources":["../src/holidays.ts"],"names":[],"mappings":";;AAEA,MAAM,YAAY,GAAkB;IAClC;QACE,KAAK,EAAE,CAAC;QACR,GAAG,EAAE,CAAC;QACN,IAAI,EAAE;YACJ,EAAE,EAAE,WAAW;YACf,EAAE,EAAE,gBAAgB;SACrB;QACD,UAAU,EAAE,KAAK;KAClB;IACD;QACE,KAA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,KAAK,KAAK,CAAC;IAC7D,CAAC,CAAC;SACD,IAAI,CAAC,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE;QACb,IACE,CAAC,CAAC,eAAe,YAAY,IAAI;YACjC,CAAC,CAAC,eAAe,YAAY,IAAI,EACjC;YACA,OAAO,CAAC,CAAC,eAAe,CAAC,OAAO,EAAE,GAAG,CAAC,CAAC,eAAe,CAAC,OAAO,EAAE,CAAC;SAClE;QAED,IACE,OAAO,CAAC,CAAC,eAAe,KAAK,QAAQ;YACrC,OAAO,CAAC,CAAC,eAAe,KAAK,QAAQ,EACrC;YACA,OAAO,CAAC,CAAC,eAAe,CAAC,aAAa,CAAC,CAAC,CAAC,eAAe,CAAC,CAAC;SAC3D;QAED,MAAM,IAAI,KAAK,CAAC,kDAAkD,CAAC,CAAC;IACtE,CAAC,CAAC,CAAC;AACP,CAAC;AA7CD,8CA6CC;AAED,kBAAe,iBAAiB,CAAC;AAEjC,+DAA+D;AAAtD,uHAAA,kBAAkB,OAAA;AAC3B,+CAA8C;AAArC,sGAAA,SAAS,OAAA;AAClB,yEAAwE;AAA/D,gIAAA,sBAAsB,OAAA"}
package/dist/types.d.ts DELETED
@@ -1,23 +0,0 @@
1
- export interface BasicHoliday {
2
- name: {
3
- en: string;
4
- es: string;
5
- };
6
- nextMonday: boolean;
7
- }
8
- export interface DateHoliday extends BasicHoliday {
9
- month: number;
10
- day: number;
11
- }
12
- export interface EasterHoliday extends BasicHoliday {
13
- offset: number;
14
- }
15
- export interface ColombianHoliday extends BasicHoliday {
16
- date: string;
17
- celebrationDate: string;
18
- }
19
- export interface ColombianHolidayWithNativeDate extends BasicHoliday {
20
- date: Date;
21
- celebrationDate: Date;
22
- }
23
- export type Holiday = DateHoliday | EasterHoliday;
package/dist/types.js DELETED
@@ -1,3 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- //# sourceMappingURL=types.js.map
package/dist/types.js.map DELETED
@@ -1 +0,0 @@
1
- {"version":3,"file":"types.js","sourceRoot":"","sources":["../src/types.ts"],"names":[],"mappings":""}
@@ -1,7 +0,0 @@
1
- import { ColombianHoliday, ColombianHolidayWithNativeDate } from "../types";
2
- export declare function getHoliday(date: Date, options: {
3
- valueAsDate: true;
4
- }): ColombianHolidayWithNativeDate | null;
5
- export declare function getHoliday(date: Date, options?: undefined | {
6
- valueAsDate: false;
7
- }): ColombianHoliday | null;
@@ -1,24 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.getHoliday = void 0;
4
- const getHolidaysByYear_1 = require("./getHolidaysByYear");
5
- const helpers_1 = require("./helpers");
6
- function getHoliday(date, options = { valueAsDate: false }) {
7
- const { valueAsDate } = options;
8
- const holiday = (0, getHolidaysByYear_1.getHolidaysForYear)(date.getUTCFullYear(), {
9
- valueAsDate: true,
10
- }).find(({ celebrationDate }) => (0, helpers_1.isSameDate)(celebrationDate, date));
11
- if (!holiday) {
12
- return null;
13
- }
14
- if (valueAsDate) {
15
- return holiday;
16
- }
17
- return {
18
- ...holiday,
19
- date: holiday.date.toISOString().slice(0, 10),
20
- celebrationDate: holiday.celebrationDate.toISOString().slice(0, 10),
21
- };
22
- }
23
- exports.getHoliday = getHoliday;
24
- //# sourceMappingURL=getHoliday.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getHoliday.js","sourceRoot":"","sources":["../../src/utils/getHoliday.ts"],"names":[],"mappings":";;;AACA,2DAAyD;AACzD,uCAAuC;AAUvC,SAAgB,UAAU,CACxB,IAAU,EACV,UAAoC,EAAE,WAAW,EAAE,KAAK,EAAE;IAE1D,MAAM,EAAE,WAAW,EAAE,GAAG,OAAO,CAAC;IAChC,MAAM,OAAO,GAAG,IAAA,sCAAkB,EAAC,IAAI,CAAC,cAAc,EAAE,EAAE;QACxD,WAAW,EAAE,IAAI;KAClB,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,eAAe,EAAE,EAAE,EAAE,CAAC,IAAA,oBAAU,EAAC,eAAe,EAAE,IAAI,CAAC,CAAC,CAAC;IACpE,IAAI,CAAC,OAAO,EAAE;QACZ,OAAO,IAAI,CAAC;KACb;IAED,IAAI,WAAW,EAAE;QACf,OAAO,OAAO,CAAC;KAChB;IACD,OAAO;QACL,GAAG,OAAO;QACV,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC;QAC7C,eAAe,EAAE,OAAO,CAAC,eAAe,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC;KACpE,CAAC;AACJ,CAAC;AApBD,gCAoBC"}
@@ -1,7 +0,0 @@
1
- import type { ColombianHolidayWithNativeDate, ColombianHoliday } from "../types";
2
- export declare function getHolidaysForYear(year: number, options?: {
3
- valueAsDate: false | undefined;
4
- }): ColombianHoliday[];
5
- export declare function getHolidaysForYear(year: number, options?: {
6
- valueAsDate: true;
7
- }): ColombianHolidayWithNativeDate[];
@@ -1,29 +0,0 @@
1
- "use strict";
2
- var __importDefault = (this && this.__importDefault) || function (mod) {
3
- return (mod && mod.__esModule) ? mod : { "default": mod };
4
- };
5
- Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.getHolidaysForYear = void 0;
7
- const __1 = __importDefault(require(".."));
8
- const holidaysWithNativeDateCache = new Map();
9
- const holidaysCache = new Map();
10
- function getHolidaysForYear(year, { valueAsDate = false } = {}) {
11
- if (valueAsDate) {
12
- const cachedHolidays = holidaysWithNativeDateCache.get(year);
13
- if (cachedHolidays) {
14
- return cachedHolidays;
15
- }
16
- const holidays = (0, __1.default)({ year, valueAsDate });
17
- holidaysWithNativeDateCache.set(year, holidays);
18
- return holidays;
19
- }
20
- const cachedHolidays = holidaysCache.get(year);
21
- if (cachedHolidays) {
22
- return cachedHolidays;
23
- }
24
- const holidays = (0, __1.default)({ year, valueAsDate });
25
- holidaysCache.set(year, holidays);
26
- return holidays;
27
- }
28
- exports.getHolidaysForYear = getHolidaysForYear;
29
- //# sourceMappingURL=getHolidaysByYear.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"getHolidaysByYear.js","sourceRoot":"","sources":["../../src/utils/getHolidaysByYear.ts"],"names":[],"mappings":";;;;;;AAAA,2CAAmC;AAMnC,MAAM,2BAA2B,GAAG,IAAI,GAAG,EAGxC,CAAC;AACJ,MAAM,aAAa,GAAG,IAAI,GAAG,EAA8B,CAAC;AAU5D,SAAgB,kBAAkB,CAChC,IAAY,EACZ,EAAE,WAAW,GAAG,KAAK,KAAgC,EAAE;IAEvD,IAAI,WAAW,EAAE;QACf,MAAM,cAAc,GAAG,2BAA2B,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC7D,IAAI,cAAc,EAAE;YAClB,OAAO,cAAc,CAAC;SACvB;QAED,MAAM,QAAQ,GAAG,IAAA,WAAiB,EAAC,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC;QAC1D,2BAA2B,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;QAChD,OAAO,QAAQ,CAAC;KACjB;IAED,MAAM,cAAc,GAAG,aAAa,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;IAC/C,IAAI,cAAc,EAAE;QAClB,OAAO,cAAc,CAAC;KACvB;IAED,MAAM,QAAQ,GAAG,IAAA,WAAiB,EAAC,EAAE,IAAI,EAAE,WAAW,EAAE,CAAC,CAAC;IAC1D,aAAa,CAAC,GAAG,CAAC,IAAI,EAAE,QAAQ,CAAC,CAAC;IAClC,OAAO,QAAQ,CAAC;AAClB,CAAC;AAvBD,gDAuBC"}
@@ -1 +0,0 @@
1
- export declare function isSameDate(date1: Date, date2: Date): boolean;
@@ -1,10 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isSameDate = void 0;
4
- function isSameDate(date1, date2) {
5
- return (date1.getUTCDate() === date2.getUTCDate() &&
6
- date1.getUTCMonth() === date2.getUTCMonth() &&
7
- date1.getUTCFullYear() === date2.getUTCFullYear());
8
- }
9
- exports.isSameDate = isSameDate;
10
- //# sourceMappingURL=helpers.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"helpers.js","sourceRoot":"","sources":["../../src/utils/helpers.ts"],"names":[],"mappings":";;;AAAA,SAAgB,UAAU,CAAC,KAAW,EAAE,KAAW;IACjD,OAAO,CACL,KAAK,CAAC,UAAU,EAAE,KAAK,KAAK,CAAC,UAAU,EAAE;QACzC,KAAK,CAAC,WAAW,EAAE,KAAK,KAAK,CAAC,WAAW,EAAE;QAC3C,KAAK,CAAC,cAAc,EAAE,KAAK,KAAK,CAAC,cAAc,EAAE,CAClD,CAAC;AACJ,CAAC;AAND,gCAMC"}
@@ -1,16 +0,0 @@
1
- import { ColombianHoliday, ColombianHolidayWithNativeDate } from "../types";
2
- export declare function holidaysWithinInterval(options: {
3
- start: Date;
4
- end: Date;
5
- valueAsDate: false | undefined;
6
- }): ColombianHoliday[];
7
- export declare function holidaysWithinInterval(options: {
8
- start: Date;
9
- end: Date;
10
- valueAsDate: true;
11
- }): ColombianHolidayWithNativeDate[];
12
- export declare function holidaysWithinInterval(options: {
13
- start: Date;
14
- end: Date;
15
- valueAsDate?: boolean;
16
- }): ColombianHoliday[] | ColombianHolidayWithNativeDate[];
@@ -1,23 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.holidaysWithinInterval = void 0;
4
- const getHolidaysByYear_1 = require("./getHolidaysByYear");
5
- function holidaysWithinInterval({ start, end, valueAsDate = false, }) {
6
- if (start >= end) {
7
- throw new Error("end date should be greater than start date");
8
- }
9
- const yearEnd = end.getUTCFullYear();
10
- const yearStart = start.getUTCFullYear();
11
- const holidays = Array.from({ length: yearEnd - yearStart + 1 }, (_, i) => (0, getHolidaysByYear_1.getHolidaysForYear)(i + yearStart, { valueAsDate: true })).flat();
12
- const holidaysWithin = holidays.filter(({ celebrationDate }) => celebrationDate >= start && celebrationDate <= end);
13
- if (valueAsDate) {
14
- return holidaysWithin;
15
- }
16
- return holidaysWithin.map((holiday) => ({
17
- ...holiday,
18
- date: holiday.date.toISOString().slice(0, 10),
19
- celebrationDate: holiday.celebrationDate.toISOString().slice(0, 10),
20
- }));
21
- }
22
- exports.holidaysWithinInterval = holidaysWithinInterval;
23
- //# sourceMappingURL=holidaysWithinInterval.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"holidaysWithinInterval.js","sourceRoot":"","sources":["../../src/utils/holidaysWithinInterval.ts"],"names":[],"mappings":";;;AACA,2DAAyD;AAiBzD,SAAgB,sBAAsB,CAAC,EACrC,KAAK,EACL,GAAG,EACH,WAAW,GAAG,KAAK,GAKpB;IACC,IAAI,KAAK,IAAI,GAAG,EAAE;QAChB,MAAM,IAAI,KAAK,CAAC,4CAA4C,CAAC,CAAC;KAC/D;IACD,MAAM,OAAO,GAAG,GAAG,CAAC,cAAc,EAAE,CAAC;IACrC,MAAM,SAAS,GAAG,KAAK,CAAC,cAAc,EAAE,CAAC;IAEzC,MAAM,QAAQ,GAAG,KAAK,CAAC,IAAI,CAAC,EAAE,MAAM,EAAE,OAAO,GAAG,SAAS,GAAG,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,CAAC,EAAE,EAAE,CACxE,IAAA,sCAAkB,EAAC,CAAC,GAAG,SAAS,EAAE,EAAE,WAAW,EAAE,IAAI,EAAE,CAAC,CACzD,CAAC,IAAI,EAAE,CAAC;IAET,MAAM,cAAc,GAAG,QAAQ,CAAC,MAAM,CACpC,CAAC,EAAE,eAAe,EAAE,EAAE,EAAE,CAAC,eAAe,IAAI,KAAK,IAAI,eAAe,IAAI,GAAG,CAC5E,CAAC;IAEF,IAAI,WAAW,EAAE;QACf,OAAO,cAAc,CAAC;KACvB;IAED,OAAO,cAAc,CAAC,GAAG,CAAC,CAAC,OAAO,EAAE,EAAE,CAAC,CAAC;QACtC,GAAG,OAAO;QACV,IAAI,EAAE,OAAO,CAAC,IAAI,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC;QAC7C,eAAe,EAAE,OAAO,CAAC,eAAe,CAAC,WAAW,EAAE,CAAC,KAAK,CAAC,CAAC,EAAE,EAAE,CAAC;KACpE,CAAC,CAAC,CAAC;AACN,CAAC;AAhCD,wDAgCC"}
@@ -1 +0,0 @@
1
- export declare function isHoliday(date: Date): boolean;
@@ -1,13 +0,0 @@
1
- "use strict";
2
- Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.isHoliday = void 0;
4
- const getHolidaysByYear_1 = require("./getHolidaysByYear");
5
- const helpers_1 = require("./helpers");
6
- function isHoliday(date) {
7
- const holidays = (0, getHolidaysByYear_1.getHolidaysForYear)(date.getUTCFullYear(), {
8
- valueAsDate: true,
9
- });
10
- return holidays.some(({ celebrationDate }) => (0, helpers_1.isSameDate)(celebrationDate, date));
11
- }
12
- exports.isHoliday = isHoliday;
13
- //# sourceMappingURL=isHoliday.js.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"isHoliday.js","sourceRoot":"","sources":["../../src/utils/isHoliday.ts"],"names":[],"mappings":";;;AAAA,2DAAyD;AACzD,uCAAuC;AAEvC,SAAgB,SAAS,CAAC,IAAU;IAClC,MAAM,QAAQ,GAAG,IAAA,sCAAkB,EAAC,IAAI,CAAC,cAAc,EAAE,EAAE;QACzD,WAAW,EAAE,IAAI;KAClB,CAAC,CAAC;IACH,OAAO,QAAQ,CAAC,IAAI,CAAC,CAAC,EAAE,eAAe,EAAE,EAAE,EAAE,CAC3C,IAAA,oBAAU,EAAC,eAAe,EAAE,IAAI,CAAC,CAClC,CAAC;AACJ,CAAC;AAPD,8BAOC"}