date-holidays
Version:
worldwide holidays
73 lines (62 loc) • 2.24 kB
JavaScript
;
var HolidaysParser = require('date-holidays-parser');
var plugins = require('date-holidays-parser/plugins');
var data = require('./data.cjs');
function _interopDefault (e) { return e && e.__esModule ? e : { default: e }; }
var HolidaysParser__default = /*#__PURE__*/_interopDefault(HolidaysParser);
/**
* @copyright 2015-present (c) commenthol
* @license ISC
*/
/** @typedef {import('date-holidays-parser').Location} Location */
/** @typedef {import('caldate').TimezoneAdapter} TimezoneAdapter */
/** @typedef {import('date-holidays-parser').HolidaysOptions} HolidaysOptions */
/**
* @class
* @param {object} data - holiday data object - see data/holidays.json
* @param {string|Location|HolidaysOptions} [country] - country code, location object, or options
* @param {string|HolidaysOptions} [state] - state or options
* @param {string|HolidaysOptions} [region] - region or options
* @param {HolidaysOptions} [opts] - options
* @example
* ```js
* new Holiday('US', 'la', 'no') // is the same as
* new Holiday('us.la.no') // is the same as
* new Holiday({ country: 'us', state: 'la', region: 'no'})
* ```
*/
class HolidaysBase extends HolidaysParser__default.default {
/** @type {TimezoneAdapter|undefined} */
static defaultTimezoneAdapter
/**
* @param {string|Location|HolidaysOptions} [country]
* @param {string|HolidaysOptions} [state]
* @param {string|HolidaysOptions} [region]
* @param {HolidaysOptions} [opts]
*/
constructor (country, state, region, opts) {
if (region && typeof region === 'object') {
opts = region;
region = undefined;
} else if (state && typeof state === 'object') {
opts = state;
state = undefined;
} else if (
country &&
typeof country === 'object' &&
!('country' in country)
) {
opts = country;
country = undefined;
}
opts = opts || {};
opts = {
...opts,
plugins: opts.plugins === undefined ? plugins.plugins : opts.plugins,
timezoneAdapter:
opts.timezoneAdapter ?? /** @type {typeof HolidaysBase} */ (new.target).defaultTimezoneAdapter
};
super(data.data, country, state, region, opts);
}
}
exports.HolidaysBase = HolidaysBase;