colombian-holidays
Advanced tools
Comparing version 2.0.2 to 3.0.0
import type { Holiday, ColombianHoliday, ColombianHolidayWithNativeDate } from "./types"; | ||
export declare const NEW_HOLIDAY_SCHEMA_START_YEAR = 1984; | ||
declare function getHoliday(holiday: Holiday, year: number, options?: undefined | { | ||
returnNativeDate?: false | undefined; | ||
declare function getHoliday(holiday: Holiday, options?: { | ||
year?: number; | ||
returnNativeDate: false | undefined; | ||
}): ColombianHoliday; | ||
declare function getHoliday(holiday: Holiday, year: number, options?: { | ||
declare function getHoliday(holiday: Holiday, options: { | ||
year?: number; | ||
returnNativeDate: true; | ||
}): ColombianHolidayWithNativeDate; | ||
declare function getHoliday(holiday: Holiday, year: number, options?: { | ||
declare function getHoliday(holiday: Holiday, options?: { | ||
year?: number; | ||
returnNativeDate?: boolean; | ||
}): ColombianHoliday | ColombianHolidayWithNativeDate; | ||
export default getHoliday; |
@@ -38,3 +38,3 @@ "use strict"; | ||
} | ||
function getHoliday(holiday, year, { returnNativeDate = false } = {}) { | ||
function getHoliday(holiday, { year = new Date().getUTCFullYear(), returnNativeDate = false, } = {}) { | ||
const holidayDate = getHolidayDate(holiday, year); | ||
@@ -41,0 +41,0 @@ const celebrationDate = year >= exports.NEW_HOLIDAY_SCHEMA_START_YEAR && holiday.nextMonday |
import { ColombianHoliday, ColombianHolidayWithNativeDate } from "./types"; | ||
export declare const FIRST_HOLIDAY_YEAR = 1583; | ||
export declare const LAST_HOLIDAY_YEAR = 4099; | ||
declare function colombianHolidays(year?: number, options?: undefined | { | ||
returnNativeDate?: false | undefined; | ||
type MonthNumbers = 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12; | ||
export type Month = MonthNumbers | Omit<number, MonthNumbers>; | ||
export declare function colombianHolidays(options?: undefined | { | ||
year?: number; | ||
month?: Month; | ||
returnNativeDate: false | undefined; | ||
}): ColombianHoliday[]; | ||
declare function colombianHolidays(year?: number, options?: { | ||
returnNativeDate?: true; | ||
export declare function colombianHolidays(options?: { | ||
year?: number; | ||
month?: Month; | ||
returnNativeDate: true; | ||
}): ColombianHolidayWithNativeDate[]; | ||
declare function colombianHolidays(year?: number, options?: { | ||
export declare function colombianHolidays(options?: { | ||
year?: number; | ||
month?: Month; | ||
returnNativeDate?: boolean; | ||
}): ColombianHoliday[] | ColombianHolidayWithNativeDate[]; | ||
export default colombianHolidays; |
@@ -6,3 +6,3 @@ "use strict"; | ||
Object.defineProperty(exports, "__esModule", { value: true }); | ||
exports.LAST_HOLIDAY_YEAR = exports.FIRST_HOLIDAY_YEAR = void 0; | ||
exports.colombianHolidays = exports.LAST_HOLIDAY_YEAR = exports.FIRST_HOLIDAY_YEAR = void 0; | ||
const helpers_1 = __importDefault(require("./helpers")); | ||
@@ -13,3 +13,3 @@ const holidays_1 = __importDefault(require("./holidays")); | ||
exports.LAST_HOLIDAY_YEAR = 4099; | ||
function colombianHolidays(year = new Date().getFullYear(), { returnNativeDate = false } = {}) { | ||
function colombianHolidays({ year = new Date().getUTCFullYear(), month, returnNativeDate = false, } = {}) { | ||
if (year < exports.FIRST_HOLIDAY_YEAR || year > exports.LAST_HOLIDAY_YEAR) { | ||
@@ -19,3 +19,12 @@ 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, { returnNativeDate })) | ||
.map((holiday) => (0, helpers_1.default)(holiday, { year, returnNativeDate })) | ||
.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) => { | ||
@@ -33,3 +42,4 @@ if (a.celebrationDate instanceof Date && | ||
} | ||
exports.colombianHolidays = colombianHolidays; | ||
exports.default = colombianHolidays; | ||
//# sourceMappingURL=index.js.map |
@@ -5,3 +5,3 @@ import { ColombianHoliday, ColombianHolidayWithNativeDate } from "../types"; | ||
end: Date; | ||
returnNativeDate?: false; | ||
returnNativeDate: false | undefined; | ||
}): ColombianHoliday[]; | ||
@@ -11,3 +11,3 @@ export declare function holidaysWithinInterval(options: { | ||
end: Date; | ||
returnNativeDate?: true; | ||
returnNativeDate: true; | ||
}): ColombianHolidayWithNativeDate[]; | ||
@@ -14,0 +14,0 @@ export declare function holidaysWithinInterval(options: { |
@@ -14,3 +14,3 @@ "use strict"; | ||
const yearStart = start.getUTCFullYear(); | ||
const holidays = Array.from({ length: yearEnd - yearStart + 1 }, (_, i) => (0, __1.default)(i + yearStart, { returnNativeDate })).flat(); | ||
const holidays = Array.from({ length: yearEnd - yearStart + 1 }, (_, i) => (0, __1.default)({ year: i + yearStart, returnNativeDate })).flat(); | ||
return holidays.filter(({ celebrationDate }) => { | ||
@@ -17,0 +17,0 @@ const date = typeof celebrationDate === "string" |
@@ -9,3 +9,3 @@ "use strict"; | ||
function isHoliday(date) { | ||
return (0, __1.default)(date.getUTCFullYear()).some(({ celebrationDate }) => { | ||
return (0, __1.default)({ year: date.getUTCFullYear() }).some(({ celebrationDate }) => { | ||
const d = new Date(celebrationDate); | ||
@@ -12,0 +12,0 @@ return (d.getUTCDate() === date.getUTCDate() && |
{ | ||
"name": "colombian-holidays", | ||
"version": "2.0.2", | ||
"version": "3.0.0", | ||
"description": "Colombian holidays", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -20,5 +20,5 @@ # Colombian Holidays 🎆 | ||
The module exports a single function to get all the holidays for a given year, returning an array with the holidays for the requested year. | ||
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. | ||
The `year` should be between 1583 and 4099. | ||
The `year` should be between 1583 and 4099 (see [Pascua](https://github.com/MauricioRobayo/pascua) package). | ||
@@ -40,3 +40,3 @@ ### CommonJS | ||
```js | ||
const colombianHolidays2015 = colombianHolidays(2015); | ||
const colombianHolidays2015 = colombianHolidays({ year: 2015 }); | ||
``` | ||
@@ -189,6 +189,43 @@ | ||
Optionally, you can request the holidays for just a given month: | ||
```js | ||
const colombianHolidays2015 = colombianHolidays({ | ||
year: 2015, | ||
month: 1 /* January */, | ||
}); | ||
``` | ||
Returns: | ||
```js | ||
[ | ||
{ | ||
date: "2015-01-01", | ||
celebrationDate: "2015-01-01", | ||
name: { | ||
es: "Año Nuevo", | ||
en: "New Year's day", | ||
}, | ||
nextMonday: false, | ||
}, | ||
{ | ||
date: "2015-01-06", | ||
celebrationDate: "2015-01-12", | ||
name: { | ||
es: "Reyes Magos", | ||
en: "Epiphany", | ||
}, | ||
nextMonday: true, | ||
}, | ||
]; | ||
``` | ||
You can opt-in to have the function return native JavaScript dates instead of strings for the `date` and `celebrationDate` properties by using the `returnNativeDate` option: | ||
```js | ||
const colombianHolidays2015 = colombianHolidays(2015, { returnNativeDate }); | ||
const colombianHolidays2015 = colombianHolidays({ | ||
year: 2015, | ||
returnNativeDate: true, | ||
}); | ||
``` | ||
@@ -199,3 +236,6 @@ | ||
```js | ||
const currentYearHolidays = colombianHolidays(); | ||
const currentYearHolidaysAsStrings = colombianHolidays(); | ||
const currentYearHolidaysAsDates = colombianHolidays({ | ||
returnNativeDate: true, | ||
}); | ||
``` | ||
@@ -202,0 +242,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
29118
359
303