UNPKG

@hebcal/core

Version:

A perpetual Jewish Calendar API

60 lines (58 loc) 1.9 kB
/*! @hebcal/core v5.10.1, distributed under GPLv2 https://www.gnu.org/licenses/gpl-2.0.txt */ const cals = new Map(); /** * Plug-ins for daily learning calendars such as Daf Yomi, Mishna Yomi, Nach Yomi, etc. * * Learning schedules are provided by the `@hebcal/learning` package. */ class DailyLearning { /** * Register a new learning calendar. * @param name case insensitive * @param calendar a function that returns an `Event` or `null` * @param startDate the first date for which this calendar is valid */ static addCalendar(name, calendar, startDate) { if (typeof calendar !== 'function') { throw new TypeError(`Invalid calendar function: ${calendar}`); } cals.set(name.toLowerCase(), { fn: calendar, startDate: startDate, }); } /** * Returns an event from daily calendar for a given date. Returns `null` if there * is no learning from this calendar on this date. * @param name case insensitive * @param hd Hebrew Date * @param il true for Israel, false for Diaspora */ static lookup(name, hd, il) { const cal = cals.get(name.toLowerCase()); if (typeof cal === 'object') { return cal.fn(hd, il); } return null; } static getStartDate(name) { const cal = cals.get(name.toLowerCase()); if (typeof cal === 'object') { return cal.startDate; } return undefined; } /** * Tests to see if learning calendar has been registered * @param name case insensitive */ static has(name) { return cals.has(name.toLowerCase()); } /** Returns the names of all calendars registered */ static getCalendars() { return Array.from(cals.keys()); } } export { DailyLearning }; //# sourceMappingURL=DailyLearning.js.map