colombian-holidays 4.0.1 → 4.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/README.md CHANGED
@@ -17,7 +17,7 @@ npm install colombian-holidays
17
17
 
18
18
  ## Usage
19
19
 
20
- The default export is a function to get all the holidays for a given year, returning an array with the holidays for the requested year.
20
+ The default export is a function to get all the holidays for a given year.
21
21
 
22
22
  The `year` should be between 1583 and 4099 (see [Pascua](https://github.com/MauricioRobayo/pascua) package).
23
23
 
@@ -231,9 +231,7 @@ If the year is omitted, by default the function will return the holidays for the
231
231
 
232
232
  ```js
233
233
  const currentYearHolidaysAsStrings = colombianHolidays();
234
- const currentYearHolidaysAsDates = colombianHolidays({
235
- valueAsDate: true,
236
- });
234
+ const currentYearHolidaysAsDates = colombianHolidays({ valueAsDate: true });
237
235
  ```
238
236
 
239
237
  ## Utils
@@ -242,12 +240,12 @@ The package provides two helper functions which can be imported from `lib/utils`
242
240
 
243
241
  ### isHoliday
244
242
 
245
- Returns true if the given date is a colombian holiday, otherwise returns false.
243
+ Returns `true` if the given date is a colombian holiday, otherwise returns `false`.
246
244
 
247
245
  ```js
248
246
  import { isHoliday } from "colombian-holidays/lib/utils/isHoliday";
249
247
 
250
- const date = new Date("2018-01-01T05:00:00.000Z");
248
+ const date = new Date("2018-01-01");
251
249
 
252
250
  if (isHoliday(date)) {
253
251
  console.log("it is a colombian holiday");
@@ -256,9 +254,35 @@ if (isHoliday(date)) {
256
254
  }
257
255
  ```
258
256
 
257
+ ### getHoliday
258
+
259
+ Similar to `isHoliday` but will return the corresponding holiday for a given date or `null` if there is no matching holiday.
260
+
261
+ ```js
262
+ import { getHoliday } from "colombian-holidays/lib/utils/getHoliday";
263
+
264
+ const date = new Date("2018-01-01");
265
+
266
+ const newYear = getHoliday(date);
267
+ /*
268
+ {
269
+ celebrationDate: "2018-01-01",
270
+ date: "2018-01-01",
271
+ name: { en: "New Year's Day", es: "Año Nuevo" },
272
+ nextMonday: false,
273
+ }
274
+ */
275
+ ```
276
+
277
+ To get the values as date use the options argument:
278
+
279
+ ```js
280
+ const newYearAsDate = getHoliday(date, { valueAsDate: true });
281
+ ```
282
+
259
283
  ### holidaysWithinInterval
260
284
 
261
- Returns an with the colombian holidays within two dates:
285
+ Returns an array with the colombian holidays within two dates:
262
286
 
263
287
  ```js
264
288
  import { holidaysWithinInterval } from "colombian-holidays/lib/utils/holidaysWithinInterval";
@@ -266,6 +290,7 @@ import { holidaysWithinInterval } from "colombian-holidays/lib/utils/holidaysWit
266
290
  const start = new Date("2021-01-01");
267
291
  const end = new Date("2021-01-11");
268
292
  const holidays = holidaysWithinInterval({ start, end });
293
+ // const holidays = holidaysWithinInterval({ start, end, valueAsDate: true });
269
294
  ```
270
295
 
271
296
  returns:
package/lib/helpers.d.ts CHANGED
@@ -1,5 +1,6 @@
1
1
  import type { Holiday, ColombianHoliday, ColombianHolidayWithNativeDate } from "./types";
2
2
  export declare const NEW_HOLIDAY_SCHEMA_START_YEAR = 1984;
3
+ export declare function generateUtcStringFromDate(date: Date): string;
3
4
  declare function getHoliday(holiday: Holiday, options?: {
4
5
  year?: number;
5
6
  valueAsDate: false | undefined;
package/lib/helpers.js CHANGED
@@ -3,7 +3,7 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
3
3
  return (mod && mod.__esModule) ? mod : { "default": mod };
4
4
  };
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
- exports.NEW_HOLIDAY_SCHEMA_START_YEAR = void 0;
6
+ exports.generateUtcStringFromDate = exports.NEW_HOLIDAY_SCHEMA_START_YEAR = void 0;
7
7
  const pascua_1 = __importDefault(require("pascua"));
8
8
  // 1984 is the year when the current holidays scheme is enforced
9
9
  // http://www.alcaldiabogota.gov.co/sisjur/normas/Norma1.jsp?i=4954
@@ -35,6 +35,7 @@ function generateUtcStringFromDateParts(year, month, day) {
35
35
  function generateUtcStringFromDate(date) {
36
36
  return generateUtcStringFromDateParts(date.getUTCFullYear(), date.getUTCMonth() + 1, date.getUTCDate());
37
37
  }
38
+ exports.generateUtcStringFromDate = generateUtcStringFromDate;
38
39
  function getHoliday(holiday, { year = new Date().getUTCFullYear(), valueAsDate = false, } = {}) {
39
40
  const holidayDate = getHolidayDate(holiday, year);
40
41
  const celebrationDate = year >= exports.NEW_HOLIDAY_SCHEMA_START_YEAR && holiday.nextMonday
@@ -1 +1 @@
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,KAAK,EAAE,CAAC,CAAC,CAAC,CAAC;QACtE,IAAI,CAAC,UAAU,CAAC,GAAG,GA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,CAAC;AAED,SAAS,8BAA8B,CACrC,IAAY,EACZ,KAAa,EACb,GAAW;IAEX,OAAO,GAAG,IAAI,IAAI,MAAM,CAAC,KAAK,CAAC,CAAC,QAAQ,CAAC,CAAC,EAAE,GAAG,CAAC,IAAI,MAAM,CAAC,GAAG,CAAC,CAAC,QAAQ,CACtE,CAAC,EACD,GAAG,CACJ,EAAE,CAAC;AACN,CAAC;AAED,SAAgB,yBAAyB,CAAC,IAAU;IAClD,OAAO,8BAA8B,CACnC,IAAI,CAAC,cAAc,EAAE,EACrB,IAAI,CAAC,WAAW,EAAE,GAAG,CAAC,EACtB,IAAI,CAAC,UAAU,EAAE,CAClB,CAAC;AACJ,CAAC;AAND,8DAMC;AAcD,SAAS,UAAU,CACjB,OAAgB,EAChB,EACE,IAAI,GAAG,IAAI,IAAI,EAAE,CAAC,cAAc,EAAE,EAClC,WAAW,GAAG,KAAK,MACyB,EAAE;IAEhD,MAAM,WAAW,GAAG,cAAc,CAAC,OAAO,EAAE,IAAI,CAAC,CAAC;IAClD,MAAM,eAAe,GACnB,IAAI,IAAI,qCAA6B,IAAI,OAAO,CAAC,UAAU;QACzD,CAAC,CAAC,aAAa,CAAC,WAAW,CAAC;QAC5B,CAAC,CAAC,WAAW,CAAC;IAElB,OAAO;QACL,IAAI,EAAE,WAAW,CAAC,CAAC,CAAC,WAAW,CAAC,CAAC,CAAC,yBAAyB,CAAC,WAAW,CAAC;QACxE,eAAe,EAAE,WAAW;YAC1B,CAAC,CAAC,eAAe;YACjB,CAAC,CAAC,yBAAyB,CAAC,eAAe,CAAC;QAC9C,IAAI,EAAE,OAAO,CAAC,IAAI;QAClB,UAAU,EAAE,IAAI,IAAI,qCAA6B,IAAI,OAAO,CAAC,UAAU;KACxE,CAAC;AACJ,CAAC;AAED,kBAAe,UAAU,CAAC"}
@@ -0,0 +1,7 @@
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;
@@ -0,0 +1,29 @@
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.getHoliday = void 0;
7
+ const __1 = __importDefault(require(".."));
8
+ const helpers_1 = require("../helpers");
9
+ const helpers_2 = require("./helpers");
10
+ function getHoliday(date, options = { valueAsDate: false }) {
11
+ const { valueAsDate } = options;
12
+ const holiday = (0, __1.default)({
13
+ year: date.getUTCFullYear(),
14
+ valueAsDate: true,
15
+ }).find(({ celebrationDate }) => (0, helpers_2.isSameDate)(celebrationDate, date));
16
+ if (!holiday) {
17
+ return null;
18
+ }
19
+ if (valueAsDate) {
20
+ return holiday;
21
+ }
22
+ return {
23
+ ...holiday,
24
+ date: (0, helpers_1.generateUtcStringFromDate)(holiday.date),
25
+ celebrationDate: (0, helpers_1.generateUtcStringFromDate)(holiday.celebrationDate),
26
+ };
27
+ }
28
+ exports.getHoliday = getHoliday;
29
+ //# sourceMappingURL=getHoliday.js.map
@@ -0,0 +1 @@
1
+ {"version":3,"file":"getHoliday.js","sourceRoot":"","sources":["../../src/utils/getHoliday.ts"],"names":[],"mappings":";;;;;;AAAA,2CAAmC;AACnC,wCAAuD;AAEvD,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,WAAiB,EAAC;QAChC,IAAI,EAAE,IAAI,CAAC,cAAc,EAAE;QAC3B,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,IAAA,mCAAyB,EAAC,OAAO,CAAC,IAAI,CAAC;QAC7C,eAAe,EAAE,IAAA,mCAAyB,EAAC,OAAO,CAAC,eAAe,CAAC;KACpE,CAAC;AACJ,CAAC;AArBD,gCAqBC"}
@@ -0,0 +1 @@
1
+ export declare function isSameDate(date1: Date, date2: Date): boolean;
@@ -0,0 +1,10 @@
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
@@ -0,0 +1 @@
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"}
@@ -5,13 +5,12 @@ var __importDefault = (this && this.__importDefault) || function (mod) {
5
5
  Object.defineProperty(exports, "__esModule", { value: true });
6
6
  exports.isHoliday = void 0;
7
7
  const __1 = __importDefault(require(".."));
8
+ const helpers_1 = require("./helpers");
8
9
  function isHoliday(date) {
9
- return (0, __1.default)({ year: date.getUTCFullYear() }).some(({ celebrationDate }) => {
10
- const d = new Date(celebrationDate);
11
- return (d.getUTCDate() === date.getUTCDate() &&
12
- d.getUTCMonth() === date.getUTCMonth() &&
13
- d.getUTCFullYear() === date.getUTCFullYear());
14
- });
10
+ return (0, __1.default)({
11
+ year: date.getUTCFullYear(),
12
+ valueAsDate: true,
13
+ }).some(({ celebrationDate }) => (0, helpers_1.isSameDate)(celebrationDate, date));
15
14
  }
16
15
  exports.isHoliday = isHoliday;
17
16
  //# sourceMappingURL=isHoliday.js.map
@@ -1 +1 @@
1
- {"version":3,"file":"isHoliday.js","sourceRoot":"","sources":["../../src/utils/isHoliday.ts"],"names":[],"mappings":";;;;;;AAAA,2CAAmC;AAEnC,SAAgB,SAAS,CAAC,IAAU;IAClC,OAAO,IAAA,WAAiB,EAAC,EAAE,IAAI,EAAE,IAAI,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC,IAAI,CAC5D,CAAC,EAAE,eAAe,EAAE,EAAE,EAAE;QACtB,MAAM,CAAC,GAAG,IAAI,IAAI,CAAC,eAAe,CAAC,CAAC;QACpC,OAAO,CACL,CAAC,CAAC,UAAU,EAAE,KAAK,IAAI,CAAC,UAAU,EAAE;YACpC,CAAC,CAAC,WAAW,EAAE,KAAK,IAAI,CAAC,WAAW,EAAE;YACtC,CAAC,CAAC,cAAc,EAAE,KAAK,IAAI,CAAC,cAAc,EAAE,CAC7C,CAAC;IACJ,CAAC,CACF,CAAC;AACJ,CAAC;AAXD,8BAWC"}
1
+ {"version":3,"file":"isHoliday.js","sourceRoot":"","sources":["../../src/utils/isHoliday.ts"],"names":[],"mappings":";;;;;;AAAA,2CAAmC;AACnC,uCAAuC;AAEvC,SAAgB,SAAS,CAAC,IAAU;IAClC,OAAO,IAAA,WAAiB,EAAC;QACvB,IAAI,EAAE,IAAI,CAAC,cAAc,EAAE;QAC3B,WAAW,EAAE,IAAI;KAClB,CAAC,CAAC,IAAI,CAAC,CAAC,EAAE,eAAe,EAAE,EAAE,EAAE,CAAC,IAAA,oBAAU,EAAC,eAAe,EAAE,IAAI,CAAC,CAAC,CAAC;AACtE,CAAC;AALD,8BAKC"}
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "colombian-holidays",
3
- "version": "4.0.1",
3
+ "version": "4.1.1",
4
4
  "description": "Colombian holidays",
5
5
  "main": "lib/index.js",
6
6
  "scripts": {