UNPKG

@hebcal/leyning

Version:

Torah Reading API for Parashat HaShavua and holidays

47 lines (44 loc) 1.25 kB
/*! @hebcal/leyning v9.2.5 */ import { BOOK } from './common.js'; import { clone } from './clone.js'; import festivals0 from './holiday-readings.json.js'; const festivals = festivals0; /** * Is there a special festival Torah Reading for `holiday`? */ function hasFestival(holiday) { return typeof festivals[holiday] === 'object'; } function aliyotBookNumToStr(aliyot) { if (aliyot) { for (const aliyah of Object.values(aliyot)) { if (typeof aliyah.k === 'number') { aliyah.k = BOOK[aliyah.k]; } } } } /** * Returns the raw metadata for festival reading for `holiday` */ function lookupFestival(holiday) { let src = festivals[holiday]; if (typeof src === 'undefined') { return undefined; } if (src.alias) { const tmp = festivals[src.key]; if (typeof tmp === 'undefined') { throw new Error(`Leyning alias ${holiday} => ${src.key} not found`); } src = tmp; } const result = src.fullkriyah ? clone(src) : src; aliyotBookNumToStr(result.fullkriyah); aliyotBookNumToStr(result.alt); if (src.note) { result.note = src.note; } return result; } export { hasFestival, lookupFestival };