UNPKG

colombian-holidays

Version:
47 lines 2.56 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.holidaysWithinInterval = exports.isHoliday = exports.getHolidaysForYear = exports.colombianHolidays = exports.LAST_HOLIDAY_YEAR = exports.FIRST_HOLIDAY_YEAR = void 0; const helpers_1 = __importDefault(require("./helpers")); const holidays_1 = __importDefault(require("./holidays")); // pascua package year limits exports.FIRST_HOLIDAY_YEAR = 1583; exports.LAST_HOLIDAY_YEAR = 4099; function colombianHolidays({ year = new Date().getUTCFullYear(), month, valueAsDate = false, } = {}) { if (year < exports.FIRST_HOLIDAY_YEAR || year > exports.LAST_HOLIDAY_YEAR) { throw new Error(`The year should be between ${exports.FIRST_HOLIDAY_YEAR} and ${exports.LAST_HOLIDAY_YEAR}`); } return holidays_1.default .map((holiday) => (0, helpers_1.default)(holiday, { year, valueAsDate })) .filter((holiday) => { if (month === undefined) { return true; } if (typeof holiday.celebrationDate === "string") { return Number(holiday.celebrationDate.slice(5, 7)) === month; } return holiday.celebrationDate.getUTCMonth() + 1 === month; }) .sort((a, b) => { if (a.celebrationDate instanceof Date && b.celebrationDate instanceof Date) { return a.celebrationDate.getTime() - b.celebrationDate.getTime(); } if (typeof a.celebrationDate === "string" && typeof b.celebrationDate === "string") { return a.celebrationDate.localeCompare(b.celebrationDate); } throw new Error("Invariant violation: this state is not possible."); }); } exports.colombianHolidays = colombianHolidays; exports.default = colombianHolidays; var getHolidaysByYear_1 = require("./utils/getHolidaysByYear"); Object.defineProperty(exports, "getHolidaysForYear", { enumerable: true, get: function () { return getHolidaysByYear_1.getHolidaysForYear; } }); var isHoliday_1 = require("./utils/isHoliday"); Object.defineProperty(exports, "isHoliday", { enumerable: true, get: function () { return isHoliday_1.isHoliday; } }); var holidaysWithinInterval_1 = require("./utils/holidaysWithinInterval"); Object.defineProperty(exports, "holidaysWithinInterval", { enumerable: true, get: function () { return holidaysWithinInterval_1.holidaysWithinInterval; } }); //# sourceMappingURL=index.js.map