@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/index.mjs CHANGED
@@ -1,346 +1,4 @@
1
- /*! @hebcal/core v5.0.1 */
2
- const GERESH = '׳';
3
- const GERSHAYIM = '״';
4
- const heb2num = {
5
- 'א': 1,
6
- 'ב': 2,
7
- 'ג': 3,
8
- 'ד': 4,
9
- 'ה': 5,
10
- 'ו': 6,
11
- 'ז': 7,
12
- 'ח': 8,
13
- 'ט': 9,
14
- 'י': 10,
15
- 'כ': 20,
16
- 'ל': 30,
17
- 'מ': 40,
18
- 'נ': 50,
19
- 'ס': 60,
20
- 'ע': 70,
21
- 'פ': 80,
22
- 'צ': 90,
23
- 'ק': 100,
24
- 'ר': 200,
25
- 'ש': 300,
26
- 'ת': 400
27
- };
28
- const num2heb = new Map();
29
- for (const [key, val] of Object.entries(heb2num)) {
30
- num2heb.set(val, key);
31
- }
32
-
33
- /**
34
- * @private
35
- * @param {number} num
36
- * @return {number[]}
37
- */
38
- function num2digits(num) {
39
- const digits = [];
40
- while (num > 0) {
41
- if (num === 15 || num === 16) {
42
- digits.push(9);
43
- digits.push(num - 9);
44
- break;
45
- }
46
- let incr = 100;
47
- let i;
48
- for (i = 400; i > num; i -= incr) {
49
- if (i === incr) {
50
- incr = incr / 10;
51
- }
52
- }
53
- digits.push(i);
54
- num -= i;
55
- }
56
- return digits;
57
- }
58
-
59
- /**
60
- * Converts a numerical value to a string of Hebrew letters.
61
- *
62
- * When specifying years of the Hebrew calendar in the present millennium,
63
- * we omit the thousands (which is presently 5 [ה]).
64
- * @example
65
- * gematriya(5774) // 'תשע״ד' - cropped to 774
66
- * gematriya(25) // 'כ״ה'
67
- * gematriya(60) // 'ס׳'
68
- * gematriya(3761) // 'ג׳תשס״א'
69
- * gematriya(1123) // 'א׳קכ״ג'
70
- * @param {number} number
71
- * @return {string}
72
- */
73
- function gematriya(number) {
74
- const num = parseInt(number, 10);
75
- if (!num) {
76
- throw new TypeError(`invalid parameter to gematriya ${number}`);
77
- }
78
- let str = '';
79
- const thousands = Math.floor(num / 1000);
80
- if (thousands > 0 && thousands !== 5) {
81
- const tdigits = num2digits(thousands);
82
- for (const tdig of tdigits) {
83
- str += num2heb.get(tdig);
84
- }
85
- str += GERESH;
86
- }
87
- const digits = num2digits(num % 1000);
88
- if (digits.length == 1) {
89
- return str + num2heb.get(digits[0]) + GERESH;
90
- }
91
- for (let i = 0; i < digits.length; i++) {
92
- if (i + 1 === digits.length) {
93
- str += GERSHAYIM;
94
- }
95
- str += num2heb.get(digits[i]);
96
- }
97
- return str;
98
- }
99
-
100
- /**
101
- * Converts a string of Hebrew letters to a numerical value.
102
- *
103
- * Only considers the value of Hebrew letters `א` through `ת`.
104
- * Ignores final Hebrew letters such as `ך` (kaf sofit) or `ם` (mem sofit)
105
- * and vowels (nekudot).
106
- *
107
- * @param {string} str
108
- * @return {number}
109
- */
110
- function gematriyaStrToNum(str) {
111
- let num = 0;
112
- const gereshIdx = str.indexOf(GERESH);
113
- if (gereshIdx !== -1 && gereshIdx !== str.length - 1) {
114
- const thousands = str.substring(0, gereshIdx);
115
- num += gematriyaStrToNum(thousands) * 1000;
116
- str = str.substring(gereshIdx);
117
- }
118
- for (const ch of str) {
119
- const n = heb2num[ch];
120
- if (typeof n === 'number') {
121
- num += n;
122
- }
123
- }
124
- return num;
125
- }
126
-
127
- const noopLocale = {
128
- headers: {
129
- 'plural-forms': 'nplurals=2; plural=(n!=1);'
130
- },
131
- contexts: {
132
- '': {}
133
- }
134
- };
135
- const alias = {
136
- 'h': 'he',
137
- 'a': 'ashkenazi',
138
- 's': 'en',
139
- '': 'en'
140
- };
141
-
142
- /** @private */
143
- const locales = new Map();
144
- /** @private */
145
- let activeLocale = null;
146
- /** @private */
147
- let activeName = null;
148
-
149
- /**
150
- * A locale in Hebcal is used for translations/transliterations of
151
- * holidays. `@hebcal/core` supports four locales by default
152
- * * `en` - default, Sephardic transliterations (e.g. "Shabbat")
153
- * * `ashkenazi` - Ashkenazi transliterations (e.g. "Shabbos")
154
- * * `he` - Hebrew (e.g. "שַׁבָּת")
155
- * * `he-x-NoNikud` - Hebrew without nikud (e.g. "שבת")
156
- */
157
- class Locale {
158
- /**
159
- * Returns translation only if `locale` offers a non-empty translation for `id`.
160
- * Otherwise, returns `undefined`.
161
- * @param {string} id Message ID to translate
162
- * @param {string} [locale] Optional locale name (i.e: `'he'`, `'fr'`). Defaults to active locale.
163
- * @return {string}
164
- */
165
- static lookupTranslation(id, locale) {
166
- const locale0 = locale === null || locale === void 0 ? void 0 : locale.toLowerCase();
167
- const loc = typeof locale == 'string' && locales.get(locale0) || activeLocale;
168
- const array = loc[id];
169
- if (array && array.length && array[0].length) {
170
- return array[0];
171
- }
172
- return undefined;
173
- }
174
-
175
- /**
176
- * By default, if no translation was found, returns `id`.
177
- * @param {string} id Message ID to translate
178
- * @param {string} [locale] Optional locale name (i.e: `'he'`, `'fr'`). Defaults to active locale.
179
- * @return {string}
180
- */
181
- static gettext(id, locale) {
182
- const text = this.lookupTranslation(id, locale);
183
- if (typeof text == 'undefined') {
184
- return id;
185
- }
186
- return text;
187
- }
188
-
189
- /**
190
- * Register locale translations.
191
- * @param {string} locale Locale name (i.e.: `'he'`, `'fr'`)
192
- * @param {LocaleData} data parsed data from a `.po` file.
193
- */
194
- static addLocale(locale, data) {
195
- if (typeof locale !== 'string') {
196
- throw new TypeError(`Invalid locale name: ${locale}`);
197
- }
198
- if (typeof data.contexts !== 'object' || typeof data.contexts[''] !== 'object') {
199
- throw new TypeError(`Locale '${locale}' invalid compact format`);
200
- }
201
- locales.set(locale.toLowerCase(), data.contexts['']);
202
- }
203
-
204
- /**
205
- * Adds a translation to `locale`, replacing any previous translation.
206
- * @param {string} locale Locale name (i.e: `'he'`, `'fr'`).
207
- * @param {string} id Message ID to translate
208
- * @param {string} translation Translation text
209
- */
210
- static addTranslation(locale, id, translation) {
211
- if (typeof locale !== 'string') {
212
- throw new TypeError(`Invalid locale name: ${locale}`);
213
- }
214
- const locale0 = locale.toLowerCase();
215
- const loc = locales.get(locale0);
216
- if (!loc) {
217
- throw new TypeError(`Unknown locale: ${locale}`);
218
- }
219
- if (typeof id !== 'string' || id.length === 0) {
220
- throw new TypeError(`Invalid id: ${id}`);
221
- }
222
- const isArray = Array.isArray(translation);
223
- if (isArray) {
224
- const t0 = translation[0];
225
- if (typeof t0 !== 'string' || t0.length === 0) {
226
- throw new TypeError(`Invalid translation array: ${translation}`);
227
- }
228
- } else if (typeof translation !== 'string') {
229
- throw new TypeError(`Invalid translation: ${translation}`);
230
- }
231
- loc[id] = isArray ? translation : [translation];
232
- }
233
- /**
234
- * Adds multiple translations to `locale`, replacing any previous translations.
235
- * @param {string} locale Locale name (i.e: `'he'`, `'fr'`).
236
- * @param {LocaleData} data parsed data from a `.po` file.
237
- */
238
- static addTranslations(locale, data) {
239
- if (typeof locale !== 'string') {
240
- throw new TypeError(`Invalid locale name: ${locale}`);
241
- }
242
- const locale0 = locale.toLowerCase();
243
- const loc = locales.get(locale0);
244
- if (!loc) {
245
- throw new TypeError(`Unknown locale: ${locale}`);
246
- }
247
- if (typeof data.contexts !== 'object' || typeof data.contexts[''] !== 'object') {
248
- throw new TypeError(`Locale '${locale}' invalid compact format`);
249
- }
250
- const ctx = data.contexts[''];
251
- Object.assign(loc, ctx);
252
- }
253
- /**
254
- * Activates a locale. Throws an error if the locale has not been previously added.
255
- * After setting the locale to be used, all strings marked for translations
256
- * will be represented by the corresponding translation in the specified locale.
257
- * @param {string} locale Locale name (i.e: `'he'`, `'fr'`)
258
- * @return {LocaleData}
259
- */
260
- static useLocale(locale) {
261
- const locale0 = locale.toLowerCase();
262
- const obj = locales.get(locale0);
263
- if (!obj) {
264
- throw new RangeError(`Locale '${locale}' not found`);
265
- }
266
- activeName = alias[locale0] || locale0;
267
- activeLocale = obj;
268
- return activeLocale;
269
- }
270
-
271
- /**
272
- * Returns the name of the active locale (i.e. 'he', 'ashkenazi', 'fr')
273
- * @return {string}
274
- */
275
- static getLocaleName() {
276
- return activeName;
277
- }
278
-
279
- /**
280
- * Returns the names of registered locales
281
- * @return {string[]}
282
- */
283
- static getLocaleNames() {
284
- const keys = Array.from(locales.keys());
285
- return keys.sort((a, b) => a.localeCompare(b));
286
- }
287
-
288
- /**
289
- * @param {number} n
290
- * @param {string} [locale] Optional locale name (i.e: `'he'`, `'fr'`). Defaults to active locale.
291
- * @return {string}
292
- */
293
- static ordinal(n, locale) {
294
- const locale1 = locale === null || locale === void 0 ? void 0 : locale.toLowerCase();
295
- const locale0 = locale1 || activeName;
296
- if (!locale0) {
297
- return this.getEnOrdinal(n);
298
- }
299
- switch (locale0) {
300
- case 'en':
301
- case 's':
302
- case 'a':
303
- case 'ashkenazi':
304
- case 'ashkenazi_litvish':
305
- case 'ashkenazi_poylish':
306
- case 'ashkenazi_standard':
307
- return this.getEnOrdinal(n);
308
- case 'es':
309
- return n + 'º';
310
- case 'h':
311
- case 'he':
312
- case 'he-x-nonikud':
313
- return String(n);
314
- default:
315
- return n + '.';
316
- }
317
- }
318
-
319
- /**
320
- * @private
321
- * @param {number} n
322
- * @return {string}
323
- */
324
- static getEnOrdinal(n) {
325
- const s = ['th', 'st', 'nd', 'rd'];
326
- const v = n % 100;
327
- return n + (s[(v - 20) % 10] || s[v] || s[0]);
328
- }
329
-
330
- /**
331
- * Removes nekudot from Hebrew string
332
- * @param {string} str
333
- * @return {string}
334
- */
335
- static hebrewStripNikkud(str) {
336
- return str.replace(/[\u0590-\u05bd]/g, '').replace(/[\u05bf-\u05c7]/g, '');
337
- }
338
- }
339
- Locale.addLocale('en', noopLocale);
340
- Locale.addLocale('s', noopLocale);
341
- Locale.addLocale('', noopLocale);
342
- Locale.useLocale('en');
343
-
1
+ /*! @hebcal/core v5.0.2 */
344
2
  /** @private */
345
3
  const lengths = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
346
4
  /** @private */
@@ -918,92 +576,429 @@ function isSimpleHebrewDate(obj) {
918
576
  typeof obj.dd === 'number';
919
577
  }
920
578
  /**
921
- * @private
579
+ * @private
580
+ */
581
+ function toSimpleHebrewDate(obj) {
582
+ if (isSimpleHebrewDate(obj)) {
583
+ return obj;
584
+ }
585
+ else if (typeof obj === 'number') {
586
+ return abs2hebrew(obj);
587
+ }
588
+ else if (greg.isDate(obj)) {
589
+ const abs = greg.greg2abs(obj);
590
+ return abs2hebrew(abs);
591
+ }
592
+ else {
593
+ throw new TypeError(`Argument not a Date: ${obj}`);
594
+ }
595
+ }
596
+ function getYahrzeitHD(hyear, date) {
597
+ let hDeath = toSimpleHebrewDate(date);
598
+ if (hyear <= hDeath.yy) {
599
+ // Hebrew year ${hyear} occurs on or before original date in ${hDeath.yy}
600
+ return undefined;
601
+ }
602
+ if (hDeath.mm == CHESHVAN && hDeath.dd == 30 && !longCheshvan(hDeath.yy + 1)) {
603
+ // If it's Heshvan 30 it depends on the first anniversary;
604
+ // if that was not Heshvan 30, use the day before Kislev 1.
605
+ hDeath = abs2hebrew(hebrew2abs(hyear, KISLEV$1, 1) - 1);
606
+ }
607
+ else if (hDeath.mm == KISLEV$1 && hDeath.dd == 30 && shortKislev(hDeath.yy + 1)) {
608
+ // If it's Kislev 30 it depends on the first anniversary;
609
+ // if that was not Kislev 30, use the day before Teveth 1.
610
+ hDeath = abs2hebrew(hebrew2abs(hyear, TEVET$1, 1) - 1);
611
+ }
612
+ else if (hDeath.mm == ADAR_II) {
613
+ // If it's Adar II, use the same day in last month of year (Adar or Adar II).
614
+ hDeath.mm = monthsInYear(hyear);
615
+ }
616
+ else if (hDeath.mm == ADAR_I$1 && hDeath.dd == 30 && !isLeapYear(hyear)) {
617
+ // If it's the 30th in Adar I and year is not a leap year
618
+ // (so Adar has only 29 days), use the last day in Shevat.
619
+ hDeath.dd = 30;
620
+ hDeath.mm = SHVAT;
621
+ }
622
+ // In all other cases, use the normal anniversary of the date of death.
623
+ // advance day to rosh chodesh if needed
624
+ if (hDeath.mm == CHESHVAN && hDeath.dd == 30 && !longCheshvan(hyear)) {
625
+ hDeath.mm = KISLEV$1;
626
+ hDeath.dd = 1;
627
+ }
628
+ else if (hDeath.mm == KISLEV$1 && hDeath.dd == 30 && shortKislev(hyear)) {
629
+ hDeath.mm = TEVET$1;
630
+ hDeath.dd = 1;
631
+ }
632
+ hDeath.yy = hyear;
633
+ return hDeath;
634
+ }
635
+ function getBirthdayHD(hyear, date) {
636
+ const orig = toSimpleHebrewDate(date);
637
+ const origYear = orig.yy;
638
+ if (hyear === origYear) {
639
+ return orig;
640
+ }
641
+ else if (hyear < origYear) {
642
+ // Hebrew year ${hyear} occurs on or before original date in ${origYear}
643
+ return undefined;
644
+ }
645
+ const isOrigLeap = isLeapYear(origYear);
646
+ let month = orig.mm;
647
+ let day = orig.dd;
648
+ if ((month == ADAR_I$1 && !isOrigLeap) || (month == ADAR_II && isOrigLeap)) {
649
+ month = monthsInYear(hyear);
650
+ }
651
+ else if (month == CHESHVAN && day == 30 && !longCheshvan(hyear)) {
652
+ month = KISLEV$1;
653
+ day = 1;
654
+ }
655
+ else if (month == KISLEV$1 && day == 30 && shortKislev(hyear)) {
656
+ month = TEVET$1;
657
+ day = 1;
658
+ }
659
+ else if (month == ADAR_I$1 && day == 30 && isOrigLeap && !isLeapYear(hyear)) {
660
+ month = NISAN$3;
661
+ day = 1;
662
+ }
663
+ return { yy: hyear, mm: month, dd: day };
664
+ }
665
+
666
+ const GERESH = '׳';
667
+ const GERSHAYIM = '״';
668
+ const alefbet = {
669
+ 'א': 1,
670
+ 'ב': 2,
671
+ 'ג': 3,
672
+ 'ד': 4,
673
+ 'ה': 5,
674
+ 'ו': 6,
675
+ 'ז': 7,
676
+ 'ח': 8,
677
+ 'ט': 9,
678
+ 'י': 10,
679
+ 'כ': 20,
680
+ 'ל': 30,
681
+ 'מ': 40,
682
+ 'נ': 50,
683
+ 'ס': 60,
684
+ 'ע': 70,
685
+ 'פ': 80,
686
+ 'צ': 90,
687
+ 'ק': 100,
688
+ 'ר': 200,
689
+ 'ש': 300,
690
+ 'ת': 400,
691
+ };
692
+ const heb2num = new Map();
693
+ const num2heb = new Map();
694
+ for (const [key, val] of Object.entries(alefbet)) {
695
+ heb2num.set(key, val);
696
+ num2heb.set(val, key);
697
+ }
698
+ function num2digits(num) {
699
+ const digits = [];
700
+ while (num > 0) {
701
+ if (num === 15 || num === 16) {
702
+ digits.push(9);
703
+ digits.push(num - 9);
704
+ break;
705
+ }
706
+ let incr = 100;
707
+ let i;
708
+ for (i = 400; i > num; i -= incr) {
709
+ if (i === incr) {
710
+ incr = incr / 10;
711
+ }
712
+ }
713
+ digits.push(i);
714
+ num -= i;
715
+ }
716
+ return digits;
717
+ }
718
+ /**
719
+ * Converts a numerical value to a string of Hebrew letters.
720
+ *
721
+ * When specifying years of the Hebrew calendar in the present millennium,
722
+ * we omit the thousands (which is presently 5 [ה]).
723
+ * @example
724
+ * gematriya(5774) // 'תשע״ד' - cropped to 774
725
+ * gematriya(25) // 'כ״ה'
726
+ * gematriya(60) // 'ס׳'
727
+ * gematriya(3761) // 'ג׳תשס״א'
728
+ * gematriya(1123) // 'א׳קכ״ג'
729
+ * @param {number} num
730
+ * @return {string}
731
+ */
732
+ function gematriya(num) {
733
+ const num0 = num;
734
+ const num1 = parseInt(num0, 10);
735
+ if (!num1) {
736
+ throw new TypeError(`invalid parameter to gematriya ${num}`);
737
+ }
738
+ let str = '';
739
+ const thousands = Math.floor(num1 / 1000);
740
+ if (thousands > 0 && thousands !== 5) {
741
+ const tdigits = num2digits(thousands);
742
+ for (const tdig of tdigits) {
743
+ str += num2heb.get(tdig);
744
+ }
745
+ str += GERESH;
746
+ }
747
+ const digits = num2digits(num1 % 1000);
748
+ if (digits.length == 1) {
749
+ return str + num2heb.get(digits[0]) + GERESH;
750
+ }
751
+ for (let i = 0; i < digits.length; i++) {
752
+ if (i + 1 === digits.length) {
753
+ str += GERSHAYIM;
754
+ }
755
+ str += num2heb.get(digits[i]);
756
+ }
757
+ return str;
758
+ }
759
+ /**
760
+ * Converts a string of Hebrew letters to a numerical value.
761
+ *
762
+ * Only considers the value of Hebrew letters `א` through `ת`.
763
+ * Ignores final Hebrew letters such as `ך` (kaf sofit) or `ם` (mem sofit)
764
+ * and vowels (nekudot).
765
+ *
766
+ * @param {string} str
767
+ * @return {number}
768
+ */
769
+ function gematriyaStrToNum(str) {
770
+ let num = 0;
771
+ const gereshIdx = str.indexOf(GERESH);
772
+ if (gereshIdx !== -1 && gereshIdx !== str.length - 1) {
773
+ const thousands = str.substring(0, gereshIdx);
774
+ num += gematriyaStrToNum(thousands) * 1000;
775
+ str = str.substring(gereshIdx);
776
+ }
777
+ for (const ch of str) {
778
+ const n = heb2num.get(ch);
779
+ if (typeof n === 'number') {
780
+ num += n;
781
+ }
782
+ }
783
+ return num;
784
+ }
785
+
786
+ const noopLocale = {
787
+ headers: {
788
+ 'plural-forms': 'nplurals=2; plural=(n!=1);'
789
+ },
790
+ contexts: {
791
+ '': {}
792
+ }
793
+ };
794
+ const alias = {
795
+ 'h': 'he',
796
+ 'a': 'ashkenazi',
797
+ 's': 'en',
798
+ '': 'en'
799
+ };
800
+
801
+ /** @private */
802
+ const locales = new Map();
803
+ /** @private */
804
+ let activeLocale = null;
805
+ /** @private */
806
+ let activeName = null;
807
+
808
+ /**
809
+ * A locale in Hebcal is used for translations/transliterations of
810
+ * holidays. `@hebcal/core` supports four locales by default
811
+ * * `en` - default, Sephardic transliterations (e.g. "Shabbat")
812
+ * * `ashkenazi` - Ashkenazi transliterations (e.g. "Shabbos")
813
+ * * `he` - Hebrew (e.g. "שַׁבָּת")
814
+ * * `he-x-NoNikud` - Hebrew without nikud (e.g. "שבת")
922
815
  */
923
- function toSimpleHebrewDate(obj) {
924
- if (isSimpleHebrewDate(obj)) {
925
- return obj;
926
- }
927
- else if (typeof obj === 'number') {
928
- return abs2hebrew(obj);
929
- }
930
- else if (greg.isDate(obj)) {
931
- const abs = greg.greg2abs(obj);
932
- return abs2hebrew(abs);
933
- }
934
- else {
935
- throw new TypeError(`Argument not a Date: ${obj}`);
816
+ class Locale {
817
+ /**
818
+ * Returns translation only if `locale` offers a non-empty translation for `id`.
819
+ * Otherwise, returns `undefined`.
820
+ * @param {string} id Message ID to translate
821
+ * @param {string} [locale] Optional locale name (i.e: `'he'`, `'fr'`). Defaults to active locale.
822
+ * @return {string}
823
+ */
824
+ static lookupTranslation(id, locale) {
825
+ const locale0 = locale === null || locale === void 0 ? void 0 : locale.toLowerCase();
826
+ const loc = typeof locale == 'string' && locales.get(locale0) || activeLocale;
827
+ const array = loc[id];
828
+ if (array && array.length && array[0].length) {
829
+ return array[0];
936
830
  }
937
- }
938
- function getYahrzeitHD(hyear, date) {
939
- let hDeath = toSimpleHebrewDate(date);
940
- if (hyear <= hDeath.yy) {
941
- // Hebrew year ${hyear} occurs on or before original date in ${hDeath.yy}
942
- return undefined;
831
+ return undefined;
832
+ }
833
+
834
+ /**
835
+ * By default, if no translation was found, returns `id`.
836
+ * @param {string} id Message ID to translate
837
+ * @param {string} [locale] Optional locale name (i.e: `'he'`, `'fr'`). Defaults to active locale.
838
+ * @return {string}
839
+ */
840
+ static gettext(id, locale) {
841
+ const text = this.lookupTranslation(id, locale);
842
+ if (typeof text == 'undefined') {
843
+ return id;
943
844
  }
944
- if (hDeath.mm == CHESHVAN && hDeath.dd == 30 && !longCheshvan(hDeath.yy + 1)) {
945
- // If it's Heshvan 30 it depends on the first anniversary;
946
- // if that was not Heshvan 30, use the day before Kislev 1.
947
- hDeath = abs2hebrew(hebrew2abs(hyear, KISLEV$1, 1) - 1);
845
+ return text;
846
+ }
847
+
848
+ /**
849
+ * Register locale translations.
850
+ * @param {string} locale Locale name (i.e.: `'he'`, `'fr'`)
851
+ * @param {LocaleData} data parsed data from a `.po` file.
852
+ */
853
+ static addLocale(locale, data) {
854
+ if (typeof locale !== 'string') {
855
+ throw new TypeError(`Invalid locale name: ${locale}`);
948
856
  }
949
- else if (hDeath.mm == KISLEV$1 && hDeath.dd == 30 && shortKislev(hDeath.yy + 1)) {
950
- // If it's Kislev 30 it depends on the first anniversary;
951
- // if that was not Kislev 30, use the day before Teveth 1.
952
- hDeath = abs2hebrew(hebrew2abs(hyear, TEVET$1, 1) - 1);
857
+ if (typeof data.contexts !== 'object' || typeof data.contexts[''] !== 'object') {
858
+ throw new TypeError(`Locale '${locale}' invalid compact format`);
953
859
  }
954
- else if (hDeath.mm == ADAR_II) {
955
- // If it's Adar II, use the same day in last month of year (Adar or Adar II).
956
- hDeath.mm = monthsInYear(hyear);
860
+ locales.set(locale.toLowerCase(), data.contexts['']);
861
+ }
862
+
863
+ /**
864
+ * Adds a translation to `locale`, replacing any previous translation.
865
+ * @param {string} locale Locale name (i.e: `'he'`, `'fr'`).
866
+ * @param {string} id Message ID to translate
867
+ * @param {string} translation Translation text
868
+ */
869
+ static addTranslation(locale, id, translation) {
870
+ if (typeof locale !== 'string') {
871
+ throw new TypeError(`Invalid locale name: ${locale}`);
957
872
  }
958
- else if (hDeath.mm == ADAR_I$1 && hDeath.dd == 30 && !isLeapYear(hyear)) {
959
- // If it's the 30th in Adar I and year is not a leap year
960
- // (so Adar has only 29 days), use the last day in Shevat.
961
- hDeath.dd = 30;
962
- hDeath.mm = SHVAT;
873
+ const locale0 = locale.toLowerCase();
874
+ const loc = locales.get(locale0);
875
+ if (!loc) {
876
+ throw new TypeError(`Unknown locale: ${locale}`);
963
877
  }
964
- // In all other cases, use the normal anniversary of the date of death.
965
- // advance day to rosh chodesh if needed
966
- if (hDeath.mm == CHESHVAN && hDeath.dd == 30 && !longCheshvan(hyear)) {
967
- hDeath.mm = KISLEV$1;
968
- hDeath.dd = 1;
878
+ if (typeof id !== 'string' || id.length === 0) {
879
+ throw new TypeError(`Invalid id: ${id}`);
969
880
  }
970
- else if (hDeath.mm == KISLEV$1 && hDeath.dd == 30 && shortKislev(hyear)) {
971
- hDeath.mm = TEVET$1;
972
- hDeath.dd = 1;
881
+ const isArray = Array.isArray(translation);
882
+ if (isArray) {
883
+ const t0 = translation[0];
884
+ if (typeof t0 !== 'string' || t0.length === 0) {
885
+ throw new TypeError(`Invalid translation array: ${translation}`);
886
+ }
887
+ } else if (typeof translation !== 'string') {
888
+ throw new TypeError(`Invalid translation: ${translation}`);
973
889
  }
974
- hDeath.yy = hyear;
975
- return hDeath;
976
- }
977
- function getBirthdayHD(hyear, date) {
978
- const orig = toSimpleHebrewDate(date);
979
- const origYear = orig.yy;
980
- if (hyear === origYear) {
981
- return orig;
890
+ loc[id] = isArray ? translation : [translation];
891
+ }
892
+ /**
893
+ * Adds multiple translations to `locale`, replacing any previous translations.
894
+ * @param {string} locale Locale name (i.e: `'he'`, `'fr'`).
895
+ * @param {LocaleData} data parsed data from a `.po` file.
896
+ */
897
+ static addTranslations(locale, data) {
898
+ if (typeof locale !== 'string') {
899
+ throw new TypeError(`Invalid locale name: ${locale}`);
982
900
  }
983
- else if (hyear < origYear) {
984
- // Hebrew year ${hyear} occurs on or before original date in ${origYear}
985
- return undefined;
901
+ const locale0 = locale.toLowerCase();
902
+ const loc = locales.get(locale0);
903
+ if (!loc) {
904
+ throw new TypeError(`Unknown locale: ${locale}`);
986
905
  }
987
- const isOrigLeap = isLeapYear(origYear);
988
- let month = orig.mm;
989
- let day = orig.dd;
990
- if ((month == ADAR_I$1 && !isOrigLeap) || (month == ADAR_II && isOrigLeap)) {
991
- month = monthsInYear(hyear);
906
+ if (typeof data.contexts !== 'object' || typeof data.contexts[''] !== 'object') {
907
+ throw new TypeError(`Locale '${locale}' invalid compact format`);
992
908
  }
993
- else if (month == CHESHVAN && day == 30 && !longCheshvan(hyear)) {
994
- month = KISLEV$1;
995
- day = 1;
909
+ const ctx = data.contexts[''];
910
+ Object.assign(loc, ctx);
911
+ }
912
+ /**
913
+ * Activates a locale. Throws an error if the locale has not been previously added.
914
+ * After setting the locale to be used, all strings marked for translations
915
+ * will be represented by the corresponding translation in the specified locale.
916
+ * @param {string} locale Locale name (i.e: `'he'`, `'fr'`)
917
+ * @return {LocaleData}
918
+ */
919
+ static useLocale(locale) {
920
+ const locale0 = locale.toLowerCase();
921
+ const obj = locales.get(locale0);
922
+ if (!obj) {
923
+ throw new RangeError(`Locale '${locale}' not found`);
996
924
  }
997
- else if (month == KISLEV$1 && day == 30 && shortKislev(hyear)) {
998
- month = TEVET$1;
999
- day = 1;
925
+ activeName = alias[locale0] || locale0;
926
+ activeLocale = obj;
927
+ return activeLocale;
928
+ }
929
+
930
+ /**
931
+ * Returns the name of the active locale (i.e. 'he', 'ashkenazi', 'fr')
932
+ * @return {string}
933
+ */
934
+ static getLocaleName() {
935
+ return activeName;
936
+ }
937
+
938
+ /**
939
+ * Returns the names of registered locales
940
+ * @return {string[]}
941
+ */
942
+ static getLocaleNames() {
943
+ const keys = Array.from(locales.keys());
944
+ return keys.sort((a, b) => a.localeCompare(b));
945
+ }
946
+
947
+ /**
948
+ * @param {number} n
949
+ * @param {string} [locale] Optional locale name (i.e: `'he'`, `'fr'`). Defaults to active locale.
950
+ * @return {string}
951
+ */
952
+ static ordinal(n, locale) {
953
+ const locale1 = locale === null || locale === void 0 ? void 0 : locale.toLowerCase();
954
+ const locale0 = locale1 || activeName;
955
+ if (!locale0) {
956
+ return this.getEnOrdinal(n);
1000
957
  }
1001
- else if (month == ADAR_I$1 && day == 30 && isOrigLeap && !isLeapYear(hyear)) {
1002
- month = NISAN$3;
1003
- day = 1;
958
+ switch (locale0) {
959
+ case 'en':
960
+ case 's':
961
+ case 'a':
962
+ case 'ashkenazi':
963
+ case 'ashkenazi_litvish':
964
+ case 'ashkenazi_poylish':
965
+ case 'ashkenazi_standard':
966
+ return this.getEnOrdinal(n);
967
+ case 'es':
968
+ return n + 'º';
969
+ case 'h':
970
+ case 'he':
971
+ case 'he-x-nonikud':
972
+ return String(n);
973
+ default:
974
+ return n + '.';
1004
975
  }
1005
- return { yy: hyear, mm: month, dd: day };
976
+ }
977
+
978
+ /**
979
+ * @private
980
+ * @param {number} n
981
+ * @return {string}
982
+ */
983
+ static getEnOrdinal(n) {
984
+ const s = ['th', 'st', 'nd', 'rd'];
985
+ const v = n % 100;
986
+ return n + (s[(v - 20) % 10] || s[v] || s[0]);
987
+ }
988
+
989
+ /**
990
+ * Removes nekudot from Hebrew string
991
+ * @param {string} str
992
+ * @return {string}
993
+ */
994
+ static hebrewStripNikkud(str) {
995
+ return str.replace(/[\u0590-\u05bd]/g, '').replace(/[\u05bf-\u05c7]/g, '');
996
+ }
1006
997
  }
998
+ Locale.addLocale('en', noopLocale);
999
+ Locale.addLocale('s', noopLocale);
1000
+ Locale.addLocale('', noopLocale);
1001
+ Locale.useLocale('en');
1007
1002
 
1008
1003
  /**
1009
1004
  * @private
@@ -5883,7 +5878,7 @@ class DailyLearning {
5883
5878
  }
5884
5879
  }
5885
5880
 
5886
- const version="5.0.1";
5881
+ const version="5.0.2";
5887
5882
 
5888
5883
  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};
5889
5884
 
@@ -6545,6 +6540,7 @@ function observedInDiaspora(ev) {
6545
6540
  return ev.observedInDiaspora();
6546
6541
  }
6547
6542
  const yearArrayCache = new Map();
6543
+ const holidaysOnDate = new Map();
6548
6544
 
6549
6545
  /**
6550
6546
  * HebrewCalendar is the main interface to the `@hebcal/core` library.
@@ -6892,20 +6888,29 @@ class HebrewCalendar {
6892
6888
  }
6893
6889
 
6894
6890
  /**
6895
- * Returns an array of Events on this date (or undefined if no events)
6891
+ * Returns an array of Events on this date (or `undefined` if no events)
6896
6892
  * @param {HDate|Date|number} date Hebrew Date, Gregorian date, or absolute R.D. day number
6897
6893
  * @param {boolean} [il] use the Israeli schedule for holidays
6898
6894
  * @return {Event[]}
6899
6895
  */
6900
6896
  static getHolidaysOnDate(date, il) {
6901
6897
  const hd = HDate.isHDate(date) ? date : new HDate(date);
6898
+ const hdStr = hd.toString();
6899
+ const cacheKey = hdStr + '/' + (typeof il === 'undefined' ? 2 : il ? 1 : 0);
6900
+ if (holidaysOnDate.has(cacheKey)) {
6901
+ return holidaysOnDate.get(cacheKey);
6902
+ }
6902
6903
  const yearMap = getHolidaysForYear_(hd.getFullYear());
6903
- const events = yearMap.get(hd.toString());
6904
+ const events = yearMap.get(hdStr);
6905
+ // if il isn't a boolean return both diaspora + IL for day
6904
6906
  if (typeof il === 'undefined' || typeof events === 'undefined') {
6907
+ holidaysOnDate.set(cacheKey, events);
6905
6908
  return events;
6906
6909
  }
6907
6910
  const myFilter = il ? observedInIsrael : observedInDiaspora;
6908
- return events.filter(myFilter);
6911
+ const filtered = events.filter(myFilter);
6912
+ holidaysOnDate.set(cacheKey, filtered);
6913
+ return filtered;
6909
6914
  }
6910
6915
 
6911
6916
  /**