@hebcal/core
Version:
A perpetual Jewish Calendar API
54 lines (51 loc) • 1.77 kB
JavaScript
/*! @hebcal/core v5.10.1, distributed under GPLv2 https://www.gnu.org/licenses/gpl-2.0.txt */
import { Event, flags } from './event.js';
import { isoDateString } from '@hebcal/hdate';
import { renderParshaName } from './parshaName.js';
import './locale.js';
/**
* Represents one of 54 weekly Torah portions, always on a Saturday
*/
class ParshaEvent extends Event {
/**
* @param parsha - untranslated name of single or double parsha,
* such as ['Bereshit'] or ['Achrei Mot', 'Kedoshim']
*/
constructor(date, parsha, il = false, num = -1) {
if (!Array.isArray(parsha) || parsha.length === 0 || parsha.length > 2) {
throw new TypeError('Bad parsha argument');
}
const desc = 'Parashat ' + parsha.join('-');
super(date, desc, flags.PARSHA_HASHAVUA);
this.parsha = parsha;
this.il = Boolean(il);
this.num = num || -1;
}
/**
* @param [locale] Optional locale name (i.e: `'he'`, `'fr'`). Defaults to active locale.
*/
render(locale) {
return renderParshaName(this.parsha, locale);
}
basename() {
return this.parsha.join('-');
}
url() {
const year = this.getDate().greg().getFullYear();
if (year < 100) {
return undefined;
}
const dt = this.urlDateSuffix();
const url = 'https://www.hebcal.com/sedrot/' +
this.basename().toLowerCase().replace(/'/g, '').replace(/ /g, '-') +
'-' +
dt;
return this.il ? url + '?i=on' : url;
}
urlDateSuffix() {
const isoDate = isoDateString(this.getDate().greg());
return isoDate.replace(/-/g, '');
}
}
export { ParshaEvent };
//# sourceMappingURL=ParshaEvent.js.map