UNPKG

@hebcal/leyning

Version:

Torah Reading API for Parashat HaShavua and holidays

42 lines (39 loc) 1.37 kB
/*! @hebcal/leyning v9.5.4 */ import { gematriya } from '@hebcal/hdate'; import './locale.js'; import { Locale } from '@hebcal/core/dist/esm/locale'; function gematriya2(num) { const str = gematriya(num); return str.replaceAll(/[׳״]/g, ''); } function formatVerseToHebrew(chapVerse) { if (chapVerse === undefined || chapVerse === null) { return ''; } const cv = chapVerse.split(':'); const chapter = parseInt(cv[0], 10); const verse = parseInt(cv[1], 10); // if not number return empty string if (isNaN(chapter) || isNaN(verse)) { return chapVerse; } return `${gematriya2(chapter)}:${gematriya2(verse)}`; } /** * Formats an aliyah object like "Numbers 28:9-15" */ function formatAliyahShort(aliyah, showBook, language = 'en') { const isEnglish = language === 'en'; const begin = isEnglish ? aliyah.b : formatVerseToHebrew(aliyah.b); const end0 = isEnglish ? aliyah.e : formatVerseToHebrew(aliyah.e); const prefix = showBook ? Locale.gettext(aliyah.k, language) + ' ' : ''; if (begin === end0) { return `${prefix}${begin}`; } const cv1 = begin.split(':'); const cv2 = end0.split(':'); const end = cv1[0] === cv2[0] ? cv2[1] : end0; return `${prefix}${begin}-${end}`; } export { formatAliyahShort, formatVerseToHebrew }; //# sourceMappingURL=format.js.map