@hebcal/core 5.0.1 → 5.0.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/bundle.js +442 -437
- package/dist/bundle.min.js +2 -2
- package/dist/index.js +422 -417
- package/dist/index.mjs +422 -417
- package/package.json +9 -9
package/dist/bundle.js
CHANGED
|
@@ -1,349 +1,7 @@
|
|
|
1
|
-
/*! @hebcal/core v5.0.
|
|
1
|
+
/*! @hebcal/core v5.0.2 */
|
|
2
2
|
var hebcal = (function (exports) {
|
|
3
3
|
'use strict';
|
|
4
4
|
|
|
5
|
-
const GERESH = '׳';
|
|
6
|
-
const GERSHAYIM = '״';
|
|
7
|
-
const heb2num = {
|
|
8
|
-
'א': 1,
|
|
9
|
-
'ב': 2,
|
|
10
|
-
'ג': 3,
|
|
11
|
-
'ד': 4,
|
|
12
|
-
'ה': 5,
|
|
13
|
-
'ו': 6,
|
|
14
|
-
'ז': 7,
|
|
15
|
-
'ח': 8,
|
|
16
|
-
'ט': 9,
|
|
17
|
-
'י': 10,
|
|
18
|
-
'כ': 20,
|
|
19
|
-
'ל': 30,
|
|
20
|
-
'מ': 40,
|
|
21
|
-
'נ': 50,
|
|
22
|
-
'ס': 60,
|
|
23
|
-
'ע': 70,
|
|
24
|
-
'פ': 80,
|
|
25
|
-
'צ': 90,
|
|
26
|
-
'ק': 100,
|
|
27
|
-
'ר': 200,
|
|
28
|
-
'ש': 300,
|
|
29
|
-
'ת': 400
|
|
30
|
-
};
|
|
31
|
-
const num2heb = new Map();
|
|
32
|
-
for (const [key, val] of Object.entries(heb2num)) {
|
|
33
|
-
num2heb.set(val, key);
|
|
34
|
-
}
|
|
35
|
-
|
|
36
|
-
/**
|
|
37
|
-
* @private
|
|
38
|
-
* @param {number} num
|
|
39
|
-
* @return {number[]}
|
|
40
|
-
*/
|
|
41
|
-
function num2digits(num) {
|
|
42
|
-
const digits = [];
|
|
43
|
-
while (num > 0) {
|
|
44
|
-
if (num === 15 || num === 16) {
|
|
45
|
-
digits.push(9);
|
|
46
|
-
digits.push(num - 9);
|
|
47
|
-
break;
|
|
48
|
-
}
|
|
49
|
-
let incr = 100;
|
|
50
|
-
let i;
|
|
51
|
-
for (i = 400; i > num; i -= incr) {
|
|
52
|
-
if (i === incr) {
|
|
53
|
-
incr = incr / 10;
|
|
54
|
-
}
|
|
55
|
-
}
|
|
56
|
-
digits.push(i);
|
|
57
|
-
num -= i;
|
|
58
|
-
}
|
|
59
|
-
return digits;
|
|
60
|
-
}
|
|
61
|
-
|
|
62
|
-
/**
|
|
63
|
-
* Converts a numerical value to a string of Hebrew letters.
|
|
64
|
-
*
|
|
65
|
-
* When specifying years of the Hebrew calendar in the present millennium,
|
|
66
|
-
* we omit the thousands (which is presently 5 [ה]).
|
|
67
|
-
* @example
|
|
68
|
-
* gematriya(5774) // 'תשע״ד' - cropped to 774
|
|
69
|
-
* gematriya(25) // 'כ״ה'
|
|
70
|
-
* gematriya(60) // 'ס׳'
|
|
71
|
-
* gematriya(3761) // 'ג׳תשס״א'
|
|
72
|
-
* gematriya(1123) // 'א׳קכ״ג'
|
|
73
|
-
* @param {number} number
|
|
74
|
-
* @return {string}
|
|
75
|
-
*/
|
|
76
|
-
function gematriya(number) {
|
|
77
|
-
const num = parseInt(number, 10);
|
|
78
|
-
if (!num) {
|
|
79
|
-
throw new TypeError(`invalid parameter to gematriya ${number}`);
|
|
80
|
-
}
|
|
81
|
-
let str = '';
|
|
82
|
-
const thousands = Math.floor(num / 1000);
|
|
83
|
-
if (thousands > 0 && thousands !== 5) {
|
|
84
|
-
const tdigits = num2digits(thousands);
|
|
85
|
-
for (const tdig of tdigits) {
|
|
86
|
-
str += num2heb.get(tdig);
|
|
87
|
-
}
|
|
88
|
-
str += GERESH;
|
|
89
|
-
}
|
|
90
|
-
const digits = num2digits(num % 1000);
|
|
91
|
-
if (digits.length == 1) {
|
|
92
|
-
return str + num2heb.get(digits[0]) + GERESH;
|
|
93
|
-
}
|
|
94
|
-
for (let i = 0; i < digits.length; i++) {
|
|
95
|
-
if (i + 1 === digits.length) {
|
|
96
|
-
str += GERSHAYIM;
|
|
97
|
-
}
|
|
98
|
-
str += num2heb.get(digits[i]);
|
|
99
|
-
}
|
|
100
|
-
return str;
|
|
101
|
-
}
|
|
102
|
-
|
|
103
|
-
/**
|
|
104
|
-
* Converts a string of Hebrew letters to a numerical value.
|
|
105
|
-
*
|
|
106
|
-
* Only considers the value of Hebrew letters `א` through `ת`.
|
|
107
|
-
* Ignores final Hebrew letters such as `ך` (kaf sofit) or `ם` (mem sofit)
|
|
108
|
-
* and vowels (nekudot).
|
|
109
|
-
*
|
|
110
|
-
* @param {string} str
|
|
111
|
-
* @return {number}
|
|
112
|
-
*/
|
|
113
|
-
function gematriyaStrToNum(str) {
|
|
114
|
-
let num = 0;
|
|
115
|
-
const gereshIdx = str.indexOf(GERESH);
|
|
116
|
-
if (gereshIdx !== -1 && gereshIdx !== str.length - 1) {
|
|
117
|
-
const thousands = str.substring(0, gereshIdx);
|
|
118
|
-
num += gematriyaStrToNum(thousands) * 1000;
|
|
119
|
-
str = str.substring(gereshIdx);
|
|
120
|
-
}
|
|
121
|
-
for (const ch of str) {
|
|
122
|
-
const n = heb2num[ch];
|
|
123
|
-
if (typeof n === 'number') {
|
|
124
|
-
num += n;
|
|
125
|
-
}
|
|
126
|
-
}
|
|
127
|
-
return num;
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
const noopLocale = {
|
|
131
|
-
headers: {
|
|
132
|
-
'plural-forms': 'nplurals=2; plural=(n!=1);'
|
|
133
|
-
},
|
|
134
|
-
contexts: {
|
|
135
|
-
'': {}
|
|
136
|
-
}
|
|
137
|
-
};
|
|
138
|
-
const alias = {
|
|
139
|
-
'h': 'he',
|
|
140
|
-
'a': 'ashkenazi',
|
|
141
|
-
's': 'en',
|
|
142
|
-
'': 'en'
|
|
143
|
-
};
|
|
144
|
-
|
|
145
|
-
/** @private */
|
|
146
|
-
const locales = new Map();
|
|
147
|
-
/** @private */
|
|
148
|
-
let activeLocale = null;
|
|
149
|
-
/** @private */
|
|
150
|
-
let activeName = null;
|
|
151
|
-
|
|
152
|
-
/**
|
|
153
|
-
* A locale in Hebcal is used for translations/transliterations of
|
|
154
|
-
* holidays. `@hebcal/core` supports four locales by default
|
|
155
|
-
* * `en` - default, Sephardic transliterations (e.g. "Shabbat")
|
|
156
|
-
* * `ashkenazi` - Ashkenazi transliterations (e.g. "Shabbos")
|
|
157
|
-
* * `he` - Hebrew (e.g. "שַׁבָּת")
|
|
158
|
-
* * `he-x-NoNikud` - Hebrew without nikud (e.g. "שבת")
|
|
159
|
-
*/
|
|
160
|
-
class Locale {
|
|
161
|
-
/**
|
|
162
|
-
* Returns translation only if `locale` offers a non-empty translation for `id`.
|
|
163
|
-
* Otherwise, returns `undefined`.
|
|
164
|
-
* @param {string} id Message ID to translate
|
|
165
|
-
* @param {string} [locale] Optional locale name (i.e: `'he'`, `'fr'`). Defaults to active locale.
|
|
166
|
-
* @return {string}
|
|
167
|
-
*/
|
|
168
|
-
static lookupTranslation(id, locale) {
|
|
169
|
-
const locale0 = locale === null || locale === void 0 ? void 0 : locale.toLowerCase();
|
|
170
|
-
const loc = typeof locale == 'string' && locales.get(locale0) || activeLocale;
|
|
171
|
-
const array = loc[id];
|
|
172
|
-
if (array && array.length && array[0].length) {
|
|
173
|
-
return array[0];
|
|
174
|
-
}
|
|
175
|
-
return undefined;
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
/**
|
|
179
|
-
* By default, if no translation was found, returns `id`.
|
|
180
|
-
* @param {string} id Message ID to translate
|
|
181
|
-
* @param {string} [locale] Optional locale name (i.e: `'he'`, `'fr'`). Defaults to active locale.
|
|
182
|
-
* @return {string}
|
|
183
|
-
*/
|
|
184
|
-
static gettext(id, locale) {
|
|
185
|
-
const text = this.lookupTranslation(id, locale);
|
|
186
|
-
if (typeof text == 'undefined') {
|
|
187
|
-
return id;
|
|
188
|
-
}
|
|
189
|
-
return text;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
/**
|
|
193
|
-
* Register locale translations.
|
|
194
|
-
* @param {string} locale Locale name (i.e.: `'he'`, `'fr'`)
|
|
195
|
-
* @param {LocaleData} data parsed data from a `.po` file.
|
|
196
|
-
*/
|
|
197
|
-
static addLocale(locale, data) {
|
|
198
|
-
if (typeof locale !== 'string') {
|
|
199
|
-
throw new TypeError(`Invalid locale name: ${locale}`);
|
|
200
|
-
}
|
|
201
|
-
if (typeof data.contexts !== 'object' || typeof data.contexts[''] !== 'object') {
|
|
202
|
-
throw new TypeError(`Locale '${locale}' invalid compact format`);
|
|
203
|
-
}
|
|
204
|
-
locales.set(locale.toLowerCase(), data.contexts['']);
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
/**
|
|
208
|
-
* Adds a translation to `locale`, replacing any previous translation.
|
|
209
|
-
* @param {string} locale Locale name (i.e: `'he'`, `'fr'`).
|
|
210
|
-
* @param {string} id Message ID to translate
|
|
211
|
-
* @param {string} translation Translation text
|
|
212
|
-
*/
|
|
213
|
-
static addTranslation(locale, id, translation) {
|
|
214
|
-
if (typeof locale !== 'string') {
|
|
215
|
-
throw new TypeError(`Invalid locale name: ${locale}`);
|
|
216
|
-
}
|
|
217
|
-
const locale0 = locale.toLowerCase();
|
|
218
|
-
const loc = locales.get(locale0);
|
|
219
|
-
if (!loc) {
|
|
220
|
-
throw new TypeError(`Unknown locale: ${locale}`);
|
|
221
|
-
}
|
|
222
|
-
if (typeof id !== 'string' || id.length === 0) {
|
|
223
|
-
throw new TypeError(`Invalid id: ${id}`);
|
|
224
|
-
}
|
|
225
|
-
const isArray = Array.isArray(translation);
|
|
226
|
-
if (isArray) {
|
|
227
|
-
const t0 = translation[0];
|
|
228
|
-
if (typeof t0 !== 'string' || t0.length === 0) {
|
|
229
|
-
throw new TypeError(`Invalid translation array: ${translation}`);
|
|
230
|
-
}
|
|
231
|
-
} else if (typeof translation !== 'string') {
|
|
232
|
-
throw new TypeError(`Invalid translation: ${translation}`);
|
|
233
|
-
}
|
|
234
|
-
loc[id] = isArray ? translation : [translation];
|
|
235
|
-
}
|
|
236
|
-
/**
|
|
237
|
-
* Adds multiple translations to `locale`, replacing any previous translations.
|
|
238
|
-
* @param {string} locale Locale name (i.e: `'he'`, `'fr'`).
|
|
239
|
-
* @param {LocaleData} data parsed data from a `.po` file.
|
|
240
|
-
*/
|
|
241
|
-
static addTranslations(locale, data) {
|
|
242
|
-
if (typeof locale !== 'string') {
|
|
243
|
-
throw new TypeError(`Invalid locale name: ${locale}`);
|
|
244
|
-
}
|
|
245
|
-
const locale0 = locale.toLowerCase();
|
|
246
|
-
const loc = locales.get(locale0);
|
|
247
|
-
if (!loc) {
|
|
248
|
-
throw new TypeError(`Unknown locale: ${locale}`);
|
|
249
|
-
}
|
|
250
|
-
if (typeof data.contexts !== 'object' || typeof data.contexts[''] !== 'object') {
|
|
251
|
-
throw new TypeError(`Locale '${locale}' invalid compact format`);
|
|
252
|
-
}
|
|
253
|
-
const ctx = data.contexts[''];
|
|
254
|
-
Object.assign(loc, ctx);
|
|
255
|
-
}
|
|
256
|
-
/**
|
|
257
|
-
* Activates a locale. Throws an error if the locale has not been previously added.
|
|
258
|
-
* After setting the locale to be used, all strings marked for translations
|
|
259
|
-
* will be represented by the corresponding translation in the specified locale.
|
|
260
|
-
* @param {string} locale Locale name (i.e: `'he'`, `'fr'`)
|
|
261
|
-
* @return {LocaleData}
|
|
262
|
-
*/
|
|
263
|
-
static useLocale(locale) {
|
|
264
|
-
const locale0 = locale.toLowerCase();
|
|
265
|
-
const obj = locales.get(locale0);
|
|
266
|
-
if (!obj) {
|
|
267
|
-
throw new RangeError(`Locale '${locale}' not found`);
|
|
268
|
-
}
|
|
269
|
-
activeName = alias[locale0] || locale0;
|
|
270
|
-
activeLocale = obj;
|
|
271
|
-
return activeLocale;
|
|
272
|
-
}
|
|
273
|
-
|
|
274
|
-
/**
|
|
275
|
-
* Returns the name of the active locale (i.e. 'he', 'ashkenazi', 'fr')
|
|
276
|
-
* @return {string}
|
|
277
|
-
*/
|
|
278
|
-
static getLocaleName() {
|
|
279
|
-
return activeName;
|
|
280
|
-
}
|
|
281
|
-
|
|
282
|
-
/**
|
|
283
|
-
* Returns the names of registered locales
|
|
284
|
-
* @return {string[]}
|
|
285
|
-
*/
|
|
286
|
-
static getLocaleNames() {
|
|
287
|
-
const keys = Array.from(locales.keys());
|
|
288
|
-
return keys.sort((a, b) => a.localeCompare(b));
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
/**
|
|
292
|
-
* @param {number} n
|
|
293
|
-
* @param {string} [locale] Optional locale name (i.e: `'he'`, `'fr'`). Defaults to active locale.
|
|
294
|
-
* @return {string}
|
|
295
|
-
*/
|
|
296
|
-
static ordinal(n, locale) {
|
|
297
|
-
const locale1 = locale === null || locale === void 0 ? void 0 : locale.toLowerCase();
|
|
298
|
-
const locale0 = locale1 || activeName;
|
|
299
|
-
if (!locale0) {
|
|
300
|
-
return this.getEnOrdinal(n);
|
|
301
|
-
}
|
|
302
|
-
switch (locale0) {
|
|
303
|
-
case 'en':
|
|
304
|
-
case 's':
|
|
305
|
-
case 'a':
|
|
306
|
-
case 'ashkenazi':
|
|
307
|
-
case 'ashkenazi_litvish':
|
|
308
|
-
case 'ashkenazi_poylish':
|
|
309
|
-
case 'ashkenazi_standard':
|
|
310
|
-
return this.getEnOrdinal(n);
|
|
311
|
-
case 'es':
|
|
312
|
-
return n + 'º';
|
|
313
|
-
case 'h':
|
|
314
|
-
case 'he':
|
|
315
|
-
case 'he-x-nonikud':
|
|
316
|
-
return String(n);
|
|
317
|
-
default:
|
|
318
|
-
return n + '.';
|
|
319
|
-
}
|
|
320
|
-
}
|
|
321
|
-
|
|
322
|
-
/**
|
|
323
|
-
* @private
|
|
324
|
-
* @param {number} n
|
|
325
|
-
* @return {string}
|
|
326
|
-
*/
|
|
327
|
-
static getEnOrdinal(n) {
|
|
328
|
-
const s = ['th', 'st', 'nd', 'rd'];
|
|
329
|
-
const v = n % 100;
|
|
330
|
-
return n + (s[(v - 20) % 10] || s[v] || s[0]);
|
|
331
|
-
}
|
|
332
|
-
|
|
333
|
-
/**
|
|
334
|
-
* Removes nekudot from Hebrew string
|
|
335
|
-
* @param {string} str
|
|
336
|
-
* @return {string}
|
|
337
|
-
*/
|
|
338
|
-
static hebrewStripNikkud(str) {
|
|
339
|
-
return str.replace(/[\u0590-\u05bd]/g, '').replace(/[\u05bf-\u05c7]/g, '');
|
|
340
|
-
}
|
|
341
|
-
}
|
|
342
|
-
Locale.addLocale('en', noopLocale);
|
|
343
|
-
Locale.addLocale('s', noopLocale);
|
|
344
|
-
Locale.addLocale('', noopLocale);
|
|
345
|
-
Locale.useLocale('en');
|
|
346
|
-
|
|
347
5
|
/** @private */
|
|
348
6
|
const lengths = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
|
|
349
7
|
/** @private */
|
|
@@ -849,104 +507,441 @@ function monthFromName(monthName) {
|
|
|
849
507
|
}
|
|
850
508
|
break;
|
|
851
509
|
}
|
|
852
|
-
throw new RangeError(`Unable to parse month name: ${monthName}`);
|
|
853
|
-
}
|
|
510
|
+
throw new RangeError(`Unable to parse month name: ${monthName}`);
|
|
511
|
+
}
|
|
512
|
+
|
|
513
|
+
const NISAN$3 = months.NISAN;
|
|
514
|
+
const CHESHVAN = months.CHESHVAN;
|
|
515
|
+
const KISLEV$1 = months.KISLEV;
|
|
516
|
+
const TEVET$1 = months.TEVET;
|
|
517
|
+
const SHVAT = months.SHVAT;
|
|
518
|
+
const ADAR_I$1 = months.ADAR_I;
|
|
519
|
+
const ADAR_II = months.ADAR_II;
|
|
520
|
+
/**
|
|
521
|
+
* Returns true if the object is a Javascript Date
|
|
522
|
+
* @private
|
|
523
|
+
* @param {Object} obj
|
|
524
|
+
*/
|
|
525
|
+
function isSimpleHebrewDate(obj) {
|
|
526
|
+
return typeof obj === 'object' && obj !== null && typeof obj.yy === 'number' && typeof obj.mm === 'number' && typeof obj.dd === 'number';
|
|
527
|
+
}
|
|
528
|
+
/**
|
|
529
|
+
* @private
|
|
530
|
+
*/
|
|
531
|
+
function toSimpleHebrewDate(obj) {
|
|
532
|
+
if (isSimpleHebrewDate(obj)) {
|
|
533
|
+
return obj;
|
|
534
|
+
} else if (typeof obj === 'number') {
|
|
535
|
+
return abs2hebrew(obj);
|
|
536
|
+
} else if (exports.greg.isDate(obj)) {
|
|
537
|
+
const abs = exports.greg.greg2abs(obj);
|
|
538
|
+
return abs2hebrew(abs);
|
|
539
|
+
} else {
|
|
540
|
+
throw new TypeError(`Argument not a Date: ${obj}`);
|
|
541
|
+
}
|
|
542
|
+
}
|
|
543
|
+
function getYahrzeitHD(hyear, date) {
|
|
544
|
+
let hDeath = toSimpleHebrewDate(date);
|
|
545
|
+
if (hyear <= hDeath.yy) {
|
|
546
|
+
// Hebrew year ${hyear} occurs on or before original date in ${hDeath.yy}
|
|
547
|
+
return undefined;
|
|
548
|
+
}
|
|
549
|
+
if (hDeath.mm == CHESHVAN && hDeath.dd == 30 && !longCheshvan(hDeath.yy + 1)) {
|
|
550
|
+
// If it's Heshvan 30 it depends on the first anniversary;
|
|
551
|
+
// if that was not Heshvan 30, use the day before Kislev 1.
|
|
552
|
+
hDeath = abs2hebrew(hebrew2abs(hyear, KISLEV$1, 1) - 1);
|
|
553
|
+
} else if (hDeath.mm == KISLEV$1 && hDeath.dd == 30 && shortKislev(hDeath.yy + 1)) {
|
|
554
|
+
// If it's Kislev 30 it depends on the first anniversary;
|
|
555
|
+
// if that was not Kislev 30, use the day before Teveth 1.
|
|
556
|
+
hDeath = abs2hebrew(hebrew2abs(hyear, TEVET$1, 1) - 1);
|
|
557
|
+
} else if (hDeath.mm == ADAR_II) {
|
|
558
|
+
// If it's Adar II, use the same day in last month of year (Adar or Adar II).
|
|
559
|
+
hDeath.mm = monthsInYear(hyear);
|
|
560
|
+
} else if (hDeath.mm == ADAR_I$1 && hDeath.dd == 30 && !isLeapYear(hyear)) {
|
|
561
|
+
// If it's the 30th in Adar I and year is not a leap year
|
|
562
|
+
// (so Adar has only 29 days), use the last day in Shevat.
|
|
563
|
+
hDeath.dd = 30;
|
|
564
|
+
hDeath.mm = SHVAT;
|
|
565
|
+
}
|
|
566
|
+
// In all other cases, use the normal anniversary of the date of death.
|
|
567
|
+
// advance day to rosh chodesh if needed
|
|
568
|
+
if (hDeath.mm == CHESHVAN && hDeath.dd == 30 && !longCheshvan(hyear)) {
|
|
569
|
+
hDeath.mm = KISLEV$1;
|
|
570
|
+
hDeath.dd = 1;
|
|
571
|
+
} else if (hDeath.mm == KISLEV$1 && hDeath.dd == 30 && shortKislev(hyear)) {
|
|
572
|
+
hDeath.mm = TEVET$1;
|
|
573
|
+
hDeath.dd = 1;
|
|
574
|
+
}
|
|
575
|
+
hDeath.yy = hyear;
|
|
576
|
+
return hDeath;
|
|
577
|
+
}
|
|
578
|
+
function getBirthdayHD(hyear, date) {
|
|
579
|
+
const orig = toSimpleHebrewDate(date);
|
|
580
|
+
const origYear = orig.yy;
|
|
581
|
+
if (hyear === origYear) {
|
|
582
|
+
return orig;
|
|
583
|
+
} else if (hyear < origYear) {
|
|
584
|
+
// Hebrew year ${hyear} occurs on or before original date in ${origYear}
|
|
585
|
+
return undefined;
|
|
586
|
+
}
|
|
587
|
+
const isOrigLeap = isLeapYear(origYear);
|
|
588
|
+
let month = orig.mm;
|
|
589
|
+
let day = orig.dd;
|
|
590
|
+
if (month == ADAR_I$1 && !isOrigLeap || month == ADAR_II && isOrigLeap) {
|
|
591
|
+
month = monthsInYear(hyear);
|
|
592
|
+
} else if (month == CHESHVAN && day == 30 && !longCheshvan(hyear)) {
|
|
593
|
+
month = KISLEV$1;
|
|
594
|
+
day = 1;
|
|
595
|
+
} else if (month == KISLEV$1 && day == 30 && shortKislev(hyear)) {
|
|
596
|
+
month = TEVET$1;
|
|
597
|
+
day = 1;
|
|
598
|
+
} else if (month == ADAR_I$1 && day == 30 && isOrigLeap && !isLeapYear(hyear)) {
|
|
599
|
+
month = NISAN$3;
|
|
600
|
+
day = 1;
|
|
601
|
+
}
|
|
602
|
+
return {
|
|
603
|
+
yy: hyear,
|
|
604
|
+
mm: month,
|
|
605
|
+
dd: day
|
|
606
|
+
};
|
|
607
|
+
}
|
|
608
|
+
|
|
609
|
+
const GERESH = '׳';
|
|
610
|
+
const GERSHAYIM = '״';
|
|
611
|
+
const alefbet = {
|
|
612
|
+
'א': 1,
|
|
613
|
+
'ב': 2,
|
|
614
|
+
'ג': 3,
|
|
615
|
+
'ד': 4,
|
|
616
|
+
'ה': 5,
|
|
617
|
+
'ו': 6,
|
|
618
|
+
'ז': 7,
|
|
619
|
+
'ח': 8,
|
|
620
|
+
'ט': 9,
|
|
621
|
+
'י': 10,
|
|
622
|
+
'כ': 20,
|
|
623
|
+
'ל': 30,
|
|
624
|
+
'מ': 40,
|
|
625
|
+
'נ': 50,
|
|
626
|
+
'ס': 60,
|
|
627
|
+
'ע': 70,
|
|
628
|
+
'פ': 80,
|
|
629
|
+
'צ': 90,
|
|
630
|
+
'ק': 100,
|
|
631
|
+
'ר': 200,
|
|
632
|
+
'ש': 300,
|
|
633
|
+
'ת': 400
|
|
634
|
+
};
|
|
635
|
+
const heb2num = new Map();
|
|
636
|
+
const num2heb = new Map();
|
|
637
|
+
for (const [key, val] of Object.entries(alefbet)) {
|
|
638
|
+
heb2num.set(key, val);
|
|
639
|
+
num2heb.set(val, key);
|
|
640
|
+
}
|
|
641
|
+
function num2digits(num) {
|
|
642
|
+
const digits = [];
|
|
643
|
+
while (num > 0) {
|
|
644
|
+
if (num === 15 || num === 16) {
|
|
645
|
+
digits.push(9);
|
|
646
|
+
digits.push(num - 9);
|
|
647
|
+
break;
|
|
648
|
+
}
|
|
649
|
+
let incr = 100;
|
|
650
|
+
let i;
|
|
651
|
+
for (i = 400; i > num; i -= incr) {
|
|
652
|
+
if (i === incr) {
|
|
653
|
+
incr = incr / 10;
|
|
654
|
+
}
|
|
655
|
+
}
|
|
656
|
+
digits.push(i);
|
|
657
|
+
num -= i;
|
|
658
|
+
}
|
|
659
|
+
return digits;
|
|
660
|
+
}
|
|
661
|
+
/**
|
|
662
|
+
* Converts a numerical value to a string of Hebrew letters.
|
|
663
|
+
*
|
|
664
|
+
* When specifying years of the Hebrew calendar in the present millennium,
|
|
665
|
+
* we omit the thousands (which is presently 5 [ה]).
|
|
666
|
+
* @example
|
|
667
|
+
* gematriya(5774) // 'תשע״ד' - cropped to 774
|
|
668
|
+
* gematriya(25) // 'כ״ה'
|
|
669
|
+
* gematriya(60) // 'ס׳'
|
|
670
|
+
* gematriya(3761) // 'ג׳תשס״א'
|
|
671
|
+
* gematriya(1123) // 'א׳קכ״ג'
|
|
672
|
+
* @param {number} num
|
|
673
|
+
* @return {string}
|
|
674
|
+
*/
|
|
675
|
+
function gematriya(num) {
|
|
676
|
+
const num0 = num;
|
|
677
|
+
const num1 = parseInt(num0, 10);
|
|
678
|
+
if (!num1) {
|
|
679
|
+
throw new TypeError(`invalid parameter to gematriya ${num}`);
|
|
680
|
+
}
|
|
681
|
+
let str = '';
|
|
682
|
+
const thousands = Math.floor(num1 / 1000);
|
|
683
|
+
if (thousands > 0 && thousands !== 5) {
|
|
684
|
+
const tdigits = num2digits(thousands);
|
|
685
|
+
for (const tdig of tdigits) {
|
|
686
|
+
str += num2heb.get(tdig);
|
|
687
|
+
}
|
|
688
|
+
str += GERESH;
|
|
689
|
+
}
|
|
690
|
+
const digits = num2digits(num1 % 1000);
|
|
691
|
+
if (digits.length == 1) {
|
|
692
|
+
return str + num2heb.get(digits[0]) + GERESH;
|
|
693
|
+
}
|
|
694
|
+
for (let i = 0; i < digits.length; i++) {
|
|
695
|
+
if (i + 1 === digits.length) {
|
|
696
|
+
str += GERSHAYIM;
|
|
697
|
+
}
|
|
698
|
+
str += num2heb.get(digits[i]);
|
|
699
|
+
}
|
|
700
|
+
return str;
|
|
701
|
+
}
|
|
702
|
+
/**
|
|
703
|
+
* Converts a string of Hebrew letters to a numerical value.
|
|
704
|
+
*
|
|
705
|
+
* Only considers the value of Hebrew letters `א` through `ת`.
|
|
706
|
+
* Ignores final Hebrew letters such as `ך` (kaf sofit) or `ם` (mem sofit)
|
|
707
|
+
* and vowels (nekudot).
|
|
708
|
+
*
|
|
709
|
+
* @param {string} str
|
|
710
|
+
* @return {number}
|
|
711
|
+
*/
|
|
712
|
+
function gematriyaStrToNum(str) {
|
|
713
|
+
let num = 0;
|
|
714
|
+
const gereshIdx = str.indexOf(GERESH);
|
|
715
|
+
if (gereshIdx !== -1 && gereshIdx !== str.length - 1) {
|
|
716
|
+
const thousands = str.substring(0, gereshIdx);
|
|
717
|
+
num += gematriyaStrToNum(thousands) * 1000;
|
|
718
|
+
str = str.substring(gereshIdx);
|
|
719
|
+
}
|
|
720
|
+
for (const ch of str) {
|
|
721
|
+
const n = heb2num.get(ch);
|
|
722
|
+
if (typeof n === 'number') {
|
|
723
|
+
num += n;
|
|
724
|
+
}
|
|
725
|
+
}
|
|
726
|
+
return num;
|
|
727
|
+
}
|
|
728
|
+
|
|
729
|
+
const noopLocale = {
|
|
730
|
+
headers: {
|
|
731
|
+
'plural-forms': 'nplurals=2; plural=(n!=1);'
|
|
732
|
+
},
|
|
733
|
+
contexts: {
|
|
734
|
+
'': {}
|
|
735
|
+
}
|
|
736
|
+
};
|
|
737
|
+
const alias = {
|
|
738
|
+
'h': 'he',
|
|
739
|
+
'a': 'ashkenazi',
|
|
740
|
+
's': 'en',
|
|
741
|
+
'': 'en'
|
|
742
|
+
};
|
|
743
|
+
|
|
744
|
+
/** @private */
|
|
745
|
+
const locales = new Map();
|
|
746
|
+
/** @private */
|
|
747
|
+
let activeLocale = null;
|
|
748
|
+
/** @private */
|
|
749
|
+
let activeName = null;
|
|
750
|
+
|
|
751
|
+
/**
|
|
752
|
+
* A locale in Hebcal is used for translations/transliterations of
|
|
753
|
+
* holidays. `@hebcal/core` supports four locales by default
|
|
754
|
+
* * `en` - default, Sephardic transliterations (e.g. "Shabbat")
|
|
755
|
+
* * `ashkenazi` - Ashkenazi transliterations (e.g. "Shabbos")
|
|
756
|
+
* * `he` - Hebrew (e.g. "שַׁבָּת")
|
|
757
|
+
* * `he-x-NoNikud` - Hebrew without nikud (e.g. "שבת")
|
|
758
|
+
*/
|
|
759
|
+
class Locale {
|
|
760
|
+
/**
|
|
761
|
+
* Returns translation only if `locale` offers a non-empty translation for `id`.
|
|
762
|
+
* Otherwise, returns `undefined`.
|
|
763
|
+
* @param {string} id Message ID to translate
|
|
764
|
+
* @param {string} [locale] Optional locale name (i.e: `'he'`, `'fr'`). Defaults to active locale.
|
|
765
|
+
* @return {string}
|
|
766
|
+
*/
|
|
767
|
+
static lookupTranslation(id, locale) {
|
|
768
|
+
const locale0 = locale === null || locale === void 0 ? void 0 : locale.toLowerCase();
|
|
769
|
+
const loc = typeof locale == 'string' && locales.get(locale0) || activeLocale;
|
|
770
|
+
const array = loc[id];
|
|
771
|
+
if (array && array.length && array[0].length) {
|
|
772
|
+
return array[0];
|
|
773
|
+
}
|
|
774
|
+
return undefined;
|
|
775
|
+
}
|
|
854
776
|
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
|
|
858
|
-
|
|
859
|
-
|
|
860
|
-
|
|
861
|
-
|
|
862
|
-
|
|
863
|
-
|
|
864
|
-
|
|
865
|
-
|
|
866
|
-
|
|
867
|
-
function isSimpleHebrewDate(obj) {
|
|
868
|
-
return typeof obj === 'object' && obj !== null && typeof obj.yy === 'number' && typeof obj.mm === 'number' && typeof obj.dd === 'number';
|
|
869
|
-
}
|
|
870
|
-
/**
|
|
871
|
-
* @private
|
|
872
|
-
*/
|
|
873
|
-
function toSimpleHebrewDate(obj) {
|
|
874
|
-
if (isSimpleHebrewDate(obj)) {
|
|
875
|
-
return obj;
|
|
876
|
-
} else if (typeof obj === 'number') {
|
|
877
|
-
return abs2hebrew(obj);
|
|
878
|
-
} else if (exports.greg.isDate(obj)) {
|
|
879
|
-
const abs = exports.greg.greg2abs(obj);
|
|
880
|
-
return abs2hebrew(abs);
|
|
881
|
-
} else {
|
|
882
|
-
throw new TypeError(`Argument not a Date: ${obj}`);
|
|
777
|
+
/**
|
|
778
|
+
* By default, if no translation was found, returns `id`.
|
|
779
|
+
* @param {string} id Message ID to translate
|
|
780
|
+
* @param {string} [locale] Optional locale name (i.e: `'he'`, `'fr'`). Defaults to active locale.
|
|
781
|
+
* @return {string}
|
|
782
|
+
*/
|
|
783
|
+
static gettext(id, locale) {
|
|
784
|
+
const text = this.lookupTranslation(id, locale);
|
|
785
|
+
if (typeof text == 'undefined') {
|
|
786
|
+
return id;
|
|
787
|
+
}
|
|
788
|
+
return text;
|
|
883
789
|
}
|
|
884
|
-
|
|
885
|
-
|
|
886
|
-
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
790
|
+
|
|
791
|
+
/**
|
|
792
|
+
* Register locale translations.
|
|
793
|
+
* @param {string} locale Locale name (i.e.: `'he'`, `'fr'`)
|
|
794
|
+
* @param {LocaleData} data parsed data from a `.po` file.
|
|
795
|
+
*/
|
|
796
|
+
static addLocale(locale, data) {
|
|
797
|
+
if (typeof locale !== 'string') {
|
|
798
|
+
throw new TypeError(`Invalid locale name: ${locale}`);
|
|
799
|
+
}
|
|
800
|
+
if (typeof data.contexts !== 'object' || typeof data.contexts[''] !== 'object') {
|
|
801
|
+
throw new TypeError(`Locale '${locale}' invalid compact format`);
|
|
802
|
+
}
|
|
803
|
+
locales.set(locale.toLowerCase(), data.contexts['']);
|
|
890
804
|
}
|
|
891
|
-
|
|
892
|
-
|
|
893
|
-
|
|
894
|
-
|
|
895
|
-
|
|
896
|
-
|
|
897
|
-
|
|
898
|
-
|
|
899
|
-
|
|
900
|
-
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
|
|
905
|
-
|
|
906
|
-
|
|
805
|
+
|
|
806
|
+
/**
|
|
807
|
+
* Adds a translation to `locale`, replacing any previous translation.
|
|
808
|
+
* @param {string} locale Locale name (i.e: `'he'`, `'fr'`).
|
|
809
|
+
* @param {string} id Message ID to translate
|
|
810
|
+
* @param {string} translation Translation text
|
|
811
|
+
*/
|
|
812
|
+
static addTranslation(locale, id, translation) {
|
|
813
|
+
if (typeof locale !== 'string') {
|
|
814
|
+
throw new TypeError(`Invalid locale name: ${locale}`);
|
|
815
|
+
}
|
|
816
|
+
const locale0 = locale.toLowerCase();
|
|
817
|
+
const loc = locales.get(locale0);
|
|
818
|
+
if (!loc) {
|
|
819
|
+
throw new TypeError(`Unknown locale: ${locale}`);
|
|
820
|
+
}
|
|
821
|
+
if (typeof id !== 'string' || id.length === 0) {
|
|
822
|
+
throw new TypeError(`Invalid id: ${id}`);
|
|
823
|
+
}
|
|
824
|
+
const isArray = Array.isArray(translation);
|
|
825
|
+
if (isArray) {
|
|
826
|
+
const t0 = translation[0];
|
|
827
|
+
if (typeof t0 !== 'string' || t0.length === 0) {
|
|
828
|
+
throw new TypeError(`Invalid translation array: ${translation}`);
|
|
829
|
+
}
|
|
830
|
+
} else if (typeof translation !== 'string') {
|
|
831
|
+
throw new TypeError(`Invalid translation: ${translation}`);
|
|
832
|
+
}
|
|
833
|
+
loc[id] = isArray ? translation : [translation];
|
|
907
834
|
}
|
|
908
|
-
|
|
909
|
-
|
|
910
|
-
|
|
911
|
-
|
|
912
|
-
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
835
|
+
/**
|
|
836
|
+
* Adds multiple translations to `locale`, replacing any previous translations.
|
|
837
|
+
* @param {string} locale Locale name (i.e: `'he'`, `'fr'`).
|
|
838
|
+
* @param {LocaleData} data parsed data from a `.po` file.
|
|
839
|
+
*/
|
|
840
|
+
static addTranslations(locale, data) {
|
|
841
|
+
if (typeof locale !== 'string') {
|
|
842
|
+
throw new TypeError(`Invalid locale name: ${locale}`);
|
|
843
|
+
}
|
|
844
|
+
const locale0 = locale.toLowerCase();
|
|
845
|
+
const loc = locales.get(locale0);
|
|
846
|
+
if (!loc) {
|
|
847
|
+
throw new TypeError(`Unknown locale: ${locale}`);
|
|
848
|
+
}
|
|
849
|
+
if (typeof data.contexts !== 'object' || typeof data.contexts[''] !== 'object') {
|
|
850
|
+
throw new TypeError(`Locale '${locale}' invalid compact format`);
|
|
851
|
+
}
|
|
852
|
+
const ctx = data.contexts[''];
|
|
853
|
+
Object.assign(loc, ctx);
|
|
916
854
|
}
|
|
917
|
-
|
|
918
|
-
|
|
919
|
-
|
|
920
|
-
|
|
921
|
-
|
|
922
|
-
|
|
923
|
-
|
|
924
|
-
|
|
925
|
-
|
|
926
|
-
|
|
927
|
-
|
|
855
|
+
/**
|
|
856
|
+
* Activates a locale. Throws an error if the locale has not been previously added.
|
|
857
|
+
* After setting the locale to be used, all strings marked for translations
|
|
858
|
+
* will be represented by the corresponding translation in the specified locale.
|
|
859
|
+
* @param {string} locale Locale name (i.e: `'he'`, `'fr'`)
|
|
860
|
+
* @return {LocaleData}
|
|
861
|
+
*/
|
|
862
|
+
static useLocale(locale) {
|
|
863
|
+
const locale0 = locale.toLowerCase();
|
|
864
|
+
const obj = locales.get(locale0);
|
|
865
|
+
if (!obj) {
|
|
866
|
+
throw new RangeError(`Locale '${locale}' not found`);
|
|
867
|
+
}
|
|
868
|
+
activeName = alias[locale0] || locale0;
|
|
869
|
+
activeLocale = obj;
|
|
870
|
+
return activeLocale;
|
|
928
871
|
}
|
|
929
|
-
|
|
930
|
-
|
|
931
|
-
|
|
932
|
-
|
|
933
|
-
|
|
934
|
-
|
|
935
|
-
|
|
936
|
-
|
|
937
|
-
|
|
938
|
-
|
|
939
|
-
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
872
|
+
|
|
873
|
+
/**
|
|
874
|
+
* Returns the name of the active locale (i.e. 'he', 'ashkenazi', 'fr')
|
|
875
|
+
* @return {string}
|
|
876
|
+
*/
|
|
877
|
+
static getLocaleName() {
|
|
878
|
+
return activeName;
|
|
879
|
+
}
|
|
880
|
+
|
|
881
|
+
/**
|
|
882
|
+
* Returns the names of registered locales
|
|
883
|
+
* @return {string[]}
|
|
884
|
+
*/
|
|
885
|
+
static getLocaleNames() {
|
|
886
|
+
const keys = Array.from(locales.keys());
|
|
887
|
+
return keys.sort((a, b) => a.localeCompare(b));
|
|
888
|
+
}
|
|
889
|
+
|
|
890
|
+
/**
|
|
891
|
+
* @param {number} n
|
|
892
|
+
* @param {string} [locale] Optional locale name (i.e: `'he'`, `'fr'`). Defaults to active locale.
|
|
893
|
+
* @return {string}
|
|
894
|
+
*/
|
|
895
|
+
static ordinal(n, locale) {
|
|
896
|
+
const locale1 = locale === null || locale === void 0 ? void 0 : locale.toLowerCase();
|
|
897
|
+
const locale0 = locale1 || activeName;
|
|
898
|
+
if (!locale0) {
|
|
899
|
+
return this.getEnOrdinal(n);
|
|
900
|
+
}
|
|
901
|
+
switch (locale0) {
|
|
902
|
+
case 'en':
|
|
903
|
+
case 's':
|
|
904
|
+
case 'a':
|
|
905
|
+
case 'ashkenazi':
|
|
906
|
+
case 'ashkenazi_litvish':
|
|
907
|
+
case 'ashkenazi_poylish':
|
|
908
|
+
case 'ashkenazi_standard':
|
|
909
|
+
return this.getEnOrdinal(n);
|
|
910
|
+
case 'es':
|
|
911
|
+
return n + 'º';
|
|
912
|
+
case 'h':
|
|
913
|
+
case 'he':
|
|
914
|
+
case 'he-x-nonikud':
|
|
915
|
+
return String(n);
|
|
916
|
+
default:
|
|
917
|
+
return n + '.';
|
|
918
|
+
}
|
|
919
|
+
}
|
|
920
|
+
|
|
921
|
+
/**
|
|
922
|
+
* @private
|
|
923
|
+
* @param {number} n
|
|
924
|
+
* @return {string}
|
|
925
|
+
*/
|
|
926
|
+
static getEnOrdinal(n) {
|
|
927
|
+
const s = ['th', 'st', 'nd', 'rd'];
|
|
928
|
+
const v = n % 100;
|
|
929
|
+
return n + (s[(v - 20) % 10] || s[v] || s[0]);
|
|
930
|
+
}
|
|
931
|
+
|
|
932
|
+
/**
|
|
933
|
+
* Removes nekudot from Hebrew string
|
|
934
|
+
* @param {string} str
|
|
935
|
+
* @return {string}
|
|
936
|
+
*/
|
|
937
|
+
static hebrewStripNikkud(str) {
|
|
938
|
+
return str.replace(/[\u0590-\u05bd]/g, '').replace(/[\u05bf-\u05c7]/g, '');
|
|
943
939
|
}
|
|
944
|
-
return {
|
|
945
|
-
yy: hyear,
|
|
946
|
-
mm: month,
|
|
947
|
-
dd: day
|
|
948
|
-
};
|
|
949
940
|
}
|
|
941
|
+
Locale.addLocale('en', noopLocale);
|
|
942
|
+
Locale.addLocale('s', noopLocale);
|
|
943
|
+
Locale.addLocale('', noopLocale);
|
|
944
|
+
Locale.useLocale('en');
|
|
950
945
|
|
|
951
946
|
/**
|
|
952
947
|
* @private
|
|
@@ -9766,7 +9761,7 @@ class DailyLearning {
|
|
|
9766
9761
|
}
|
|
9767
9762
|
}
|
|
9768
9763
|
|
|
9769
|
-
const version="5.0.
|
|
9764
|
+
const version="5.0.2";
|
|
9770
9765
|
|
|
9771
9766
|
const headers$1={"plural-forms":"nplurals=2; plural=(n > 1);"};const contexts$1={"":{Shabbat:["Shabbos"],"Achrei Mot":["Achrei Mos"],Bechukotai:["Bechukosai"],"Beha'alotcha":["Beha'aloscha"],Bereshit:["Bereshis"],Chukat:["Chukas"],"Erev Shavuot":["Erev Shavuos"],"Erev Sukkot":["Erev Sukkos"],"Ki Tavo":["Ki Savo"],"Ki Teitzei":["Ki Seitzei"],"Ki Tisa":["Ki Sisa"],Matot:["Matos"],"Purim Katan":["Purim Koton"],"Shabbat Chazon":["Shabbos Chazon"],"Shabbat HaChodesh":["Shabbos HaChodesh"],"Shabbat HaGadol":["Shabbos HaGadol"],"Shabbat Nachamu":["Shabbos Nachamu"],"Shabbat Parah":["Shabbos Parah"],"Shabbat Shekalim":["Shabbos Shekalim"],"Shabbat Shuva":["Shabbos Shuvah"],"Shabbat Zachor":["Shabbos Zachor"],Shavuot:["Shavuos"],"Shavuot I":["Shavuos I"],"Shavuot II":["Shavuos II"],Shemot:["Shemos"],"Shmini Atzeret":["Shmini Atzeres"],"Simchat Torah":["Simchas Torah"],Sukkot:["Sukkos"],"Sukkot I":["Sukkos I"],"Sukkot II":["Sukkos II"],"Sukkot II (CH''M)":["Sukkos II (CH''M)"],"Sukkot III (CH''M)":["Sukkos III (CH''M)"],"Sukkot IV (CH''M)":["Sukkos IV (CH''M)"],"Sukkot V (CH''M)":["Sukkos V (CH''M)"],"Sukkot VI (CH''M)":["Sukkos VI (CH''M)"],"Sukkot VII (Hoshana Raba)":["Sukkos VII (Hoshana Raba)"],"Ta'anit Bechorot":["Ta'anis Bechoros"],"Ta'anit Esther":["Ta'anis Esther"],Toldot:["Toldos"],Vaetchanan:["Vaeschanan"],Yitro:["Yisro"],"Vezot Haberakhah":["Vezos Haberakhah"],Parashat:["Parshas"],"Leil Selichot":["Leil Selichos"],"Shabbat Mevarchim Chodesh":["Shabbos Mevorchim Chodesh"],"Shabbat Shirah":["Shabbos Shirah"],Tevet:["Teves"],"Asara B'Tevet":["Asara B'Teves"],"Alot HaShachar":["Alos HaShachar"],"Kriat Shema, sof zeman":["Krias Shema, sof zman"],"Tefilah, sof zeman":["Tefilah, sof zman"],"Kriat Shema, sof zeman (MGA)":["Krias Shema, sof zman (MGA)"],"Tefilah, sof zeman (MGA)":["Tefilah, sof zman (MGA)"],"Chatzot HaLailah":["Chatzos HaLailah"],"Chatzot hayom":["Chatzos"],"Tzeit HaKochavim":["Tzeis HaKochavim"],"Birkat Hachamah":["Birkas Hachamah"],"Shushan Purim Katan":["Shushan Purim Koton"]}};var poAshkenazi = {headers:headers$1,contexts:contexts$1};
|
|
9772
9767
|
|
|
@@ -10940,6 +10935,7 @@ function observedInDiaspora(ev) {
|
|
|
10940
10935
|
return ev.observedInDiaspora();
|
|
10941
10936
|
}
|
|
10942
10937
|
const yearArrayCache = new Map();
|
|
10938
|
+
const holidaysOnDate = new Map();
|
|
10943
10939
|
|
|
10944
10940
|
/**
|
|
10945
10941
|
* HebrewCalendar is the main interface to the `@hebcal/core` library.
|
|
@@ -11288,20 +11284,29 @@ class HebrewCalendar {
|
|
|
11288
11284
|
}
|
|
11289
11285
|
|
|
11290
11286
|
/**
|
|
11291
|
-
* Returns an array of Events on this date (or undefined if no events)
|
|
11287
|
+
* Returns an array of Events on this date (or `undefined` if no events)
|
|
11292
11288
|
* @param {HDate|Date|number} date Hebrew Date, Gregorian date, or absolute R.D. day number
|
|
11293
11289
|
* @param {boolean} [il] use the Israeli schedule for holidays
|
|
11294
11290
|
* @return {Event[]}
|
|
11295
11291
|
*/
|
|
11296
11292
|
static getHolidaysOnDate(date, il) {
|
|
11297
11293
|
const hd = HDate.isHDate(date) ? date : new HDate(date);
|
|
11294
|
+
const hdStr = hd.toString();
|
|
11295
|
+
const cacheKey = hdStr + '/' + (typeof il === 'undefined' ? 2 : il ? 1 : 0);
|
|
11296
|
+
if (holidaysOnDate.has(cacheKey)) {
|
|
11297
|
+
return holidaysOnDate.get(cacheKey);
|
|
11298
|
+
}
|
|
11298
11299
|
const yearMap = getHolidaysForYear_(hd.getFullYear());
|
|
11299
|
-
const events = yearMap.get(
|
|
11300
|
+
const events = yearMap.get(hdStr);
|
|
11301
|
+
// if il isn't a boolean return both diaspora + IL for day
|
|
11300
11302
|
if (typeof il === 'undefined' || typeof events === 'undefined') {
|
|
11303
|
+
holidaysOnDate.set(cacheKey, events);
|
|
11301
11304
|
return events;
|
|
11302
11305
|
}
|
|
11303
11306
|
const myFilter = il ? observedInIsrael : observedInDiaspora;
|
|
11304
|
-
|
|
11307
|
+
const filtered = events.filter(myFilter);
|
|
11308
|
+
holidaysOnDate.set(cacheKey, filtered);
|
|
11309
|
+
return filtered;
|
|
11305
11310
|
}
|
|
11306
11311
|
|
|
11307
11312
|
/**
|