@hebcal/core 5.4.10 → 5.4.11

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 CHANGED
@@ -1,4 +1,4 @@
1
- /*! @hebcal/core v5.4.10 */
1
+ /*! @hebcal/core v5.4.11 */
2
2
  var hebcal = (function (exports) {
3
3
  'use strict';
4
4
 
@@ -139,15 +139,15 @@ exports.greg.isLeapYear = isGregLeapYear;
139
139
  */
140
140
  const NISAN$4 = 1;
141
141
  const IYYAR$1 = 2;
142
- // const SIVAN = 3;
142
+ const SIVAN$1 = 3;
143
143
  const TAMUZ$1 = 4;
144
- // const AV = 5;
144
+ const AV$1 = 5;
145
145
  const ELUL$1 = 6;
146
146
  const TISHREI$3 = 7;
147
147
  const CHESHVAN$1 = 8;
148
148
  const KISLEV$2 = 9;
149
149
  const TEVET$2 = 10;
150
- // const SHVAT = 11;
150
+ const SHVAT$1 = 11;
151
151
  const ADAR_I$2 = 12;
152
152
  const ADAR_II$2 = 13;
153
153
  /**
@@ -157,31 +157,31 @@ const ADAR_II$2 = 13;
157
157
  */
158
158
  const months = {
159
159
  /** Nissan / ניסן */
160
- NISAN: 1,
160
+ NISAN: NISAN$4,
161
161
  /** Iyyar / אייר */
162
- IYYAR: 2,
162
+ IYYAR: IYYAR$1,
163
163
  /** Sivan / סיון */
164
- SIVAN: 3,
164
+ SIVAN: SIVAN$1,
165
165
  /** Tamuz (sometimes Tammuz) / תמוז */
166
- TAMUZ: 4,
166
+ TAMUZ: TAMUZ$1,
167
167
  /** Av / אב */
168
- AV: 5,
168
+ AV: AV$1,
169
169
  /** Elul / אלול */
170
- ELUL: 6,
170
+ ELUL: ELUL$1,
171
171
  /** Tishrei / תִּשְׁרֵי */
172
- TISHREI: 7,
172
+ TISHREI: TISHREI$3,
173
173
  /** Cheshvan / חשון */
174
- CHESHVAN: 8,
174
+ CHESHVAN: CHESHVAN$1,
175
175
  /** Kislev / כסלו */
176
- KISLEV: 9,
176
+ KISLEV: KISLEV$2,
177
177
  /** Tevet / טבת */
178
- TEVET: 10,
178
+ TEVET: TEVET$2,
179
179
  /** Sh'vat / שבט */
180
- SHVAT: 11,
180
+ SHVAT: SHVAT$1,
181
181
  /** Adar or Adar Rishon / אדר */
182
- ADAR_I: 12,
182
+ ADAR_I: ADAR_I$2,
183
183
  /** Adar Sheini (only on leap years) / אדר ב׳ */
184
- ADAR_II: 13
184
+ ADAR_II: ADAR_II$2
185
185
  };
186
186
  const monthNames0 = ['', 'Nisan', 'Iyyar', 'Sivan', 'Tamuz', 'Av', 'Elul', 'Tishrei', 'Cheshvan', 'Kislev', 'Tevet', "Sh'vat"];
187
187
  /**
@@ -420,74 +420,74 @@ function monthFromName(monthName) {
420
420
  if (c[1] === 'o') {
421
421
  break; /* this catches "november" */
422
422
  }
423
- return months.NISAN;
423
+ return NISAN$4;
424
424
  case 'i':
425
- return months.IYYAR;
425
+ return IYYAR$1;
426
426
  case 'e':
427
- return months.ELUL;
427
+ return ELUL$1;
428
428
  case 'c':
429
429
  case 'ח':
430
- return months.CHESHVAN;
430
+ return CHESHVAN$1;
431
431
  case 'k':
432
432
  case 'כ':
433
- return months.KISLEV;
433
+ return KISLEV$2;
434
434
  case 's':
435
435
  switch (c[1]) {
436
436
  case 'i':
437
- return months.SIVAN;
437
+ return SIVAN$1;
438
438
  case 'h':
439
- return months.SHVAT;
439
+ return SHVAT$1;
440
440
  }
441
441
  break;
442
442
  case 't':
443
443
  switch (c[1]) {
444
444
  case 'a':
445
- return months.TAMUZ;
445
+ return TAMUZ$1;
446
446
  case 'i':
447
- return months.TISHREI;
447
+ return TISHREI$3;
448
448
  case 'e':
449
- return months.TEVET;
449
+ return TEVET$2;
450
450
  }
451
451
  break;
452
452
  case 'a':
453
453
  switch (c[1]) {
454
454
  case 'v':
455
- return months.AV;
455
+ return AV$1;
456
456
  case 'd':
457
457
  if (/(1|[^i]i|a|א)$/i.test(monthName)) {
458
- return months.ADAR_I;
458
+ return ADAR_I$2;
459
459
  }
460
- return months.ADAR_II;
460
+ return ADAR_II$2;
461
461
  }
462
462
  break;
463
463
  case 'ס':
464
- return months.SIVAN;
464
+ return SIVAN$1;
465
465
  case 'ט':
466
- return months.TEVET;
466
+ return TEVET$2;
467
467
  case 'ש':
468
- return months.SHVAT;
468
+ return SHVAT$1;
469
469
  case 'א':
470
470
  switch (c[1]) {
471
471
  case 'ב':
472
- return months.AV;
472
+ return AV$1;
473
473
  case 'ד':
474
474
  if (/(1|[^i]i|a|א)$/i.test(monthName)) {
475
- return months.ADAR_I;
475
+ return ADAR_I$2;
476
476
  }
477
- return months.ADAR_II;
477
+ return ADAR_II$2;
478
478
  // else assume sheini
479
479
  case 'י':
480
- return months.IYYAR;
480
+ return IYYAR$1;
481
481
  case 'ל':
482
- return months.ELUL;
482
+ return ELUL$1;
483
483
  }
484
484
  break;
485
485
  case 'ת':
486
486
  switch (c[1]) {
487
487
  case 'מ':
488
- return months.TAMUZ;
488
+ return TAMUZ$1;
489
489
  case 'ש':
490
- return months.TISHREI;
490
+ return TISHREI$3;
491
491
  }
492
492
  break;
493
493
  }
@@ -514,13 +514,12 @@ function isSimpleHebrewDate$1(obj) {
514
514
  function toSimpleHebrewDate(obj) {
515
515
  if (isSimpleHebrewDate$1(obj)) {
516
516
  return obj;
517
- } else if (typeof obj === 'number') {
518
- return abs2hebrew(obj);
519
517
  } else if (isDate(obj)) {
520
518
  const abs = greg2abs(obj);
521
519
  return abs2hebrew(abs);
522
520
  } else {
523
- throw new TypeError(`Argument not a Date: ${obj}`);
521
+ // typeof obj === 'number'
522
+ return abs2hebrew(obj);
524
523
  }
525
524
  }
526
525
  function getYahrzeitHD(hyear, date) {
@@ -656,8 +655,8 @@ function num2digits(num) {
656
655
  function gematriya(num) {
657
656
  const num0 = num;
658
657
  const num1 = parseInt(num0, 10);
659
- if (!num1) {
660
- throw new TypeError(`invalid parameter to gematriya ${num}`);
658
+ if (!num1 || num1 < 0) {
659
+ throw new TypeError(`invalid gematriya number: ${num}`);
661
660
  }
662
661
  let str = '';
663
662
  const thousands = Math.floor(num1 / 1000);
@@ -908,6 +907,35 @@ function molad(year, month) {
908
907
  };
909
908
  }
910
909
 
910
+ /**
911
+ * Formats a number with leading zeros so the resulting string is 4 digits long.
912
+ * Similar to `string.padStart(4, '0')` but will also format
913
+ * negative numbers similar to how the JavaScript date formats
914
+ * negative year numbers (e.g. `-37` is formatted as `-000037`).
915
+ */
916
+ function pad4(num) {
917
+ if (num < 0) {
918
+ return '-00' + pad4(-num);
919
+ } else if (num < 10) {
920
+ return '000' + num;
921
+ } else if (num < 100) {
922
+ return '00' + num;
923
+ } else if (num < 1000) {
924
+ return '0' + num;
925
+ }
926
+ return String(num);
927
+ }
928
+ /**
929
+ * Formats a number with leading zeros so the resulting string is 2 digits long.
930
+ * Similar to `string.padStart(2, '0')`.
931
+ */
932
+ function pad2(num) {
933
+ if (num >= 0 && num < 10) {
934
+ return '0' + num;
935
+ }
936
+ return String(num);
937
+ }
938
+
911
939
  const _formatters = new Map();
912
940
  /**
913
941
  * @private
@@ -956,34 +984,6 @@ function getTimezoneOffset(tzid, date) {
956
984
  const diffMs = new Date(utcStr).getTime() - new Date(localStr).getTime();
957
985
  return Math.ceil(diffMs / 1000 / 60);
958
986
  }
959
- /**
960
- * Formats a number with leading zeros so the resulting string is 4 digits long.
961
- * Similar to `string.padStart(4, '0')` but will also format
962
- * negative numbers similar to how the JavaScript date formats
963
- * negative year numbers (e.g. `-37` is formatted as `-000037`).
964
- */
965
- function pad4(number) {
966
- if (number < 0) {
967
- return '-00' + pad4(-number);
968
- } else if (number < 10) {
969
- return '000' + number;
970
- } else if (number < 100) {
971
- return '00' + number;
972
- } else if (number < 1000) {
973
- return '0' + number;
974
- }
975
- return String(number);
976
- }
977
- /**
978
- * Formats a number with leading zeros so the resulting string is 2 digits long.
979
- * Similar to `string.padStart(2, '0')`.
980
- */
981
- function pad2(number) {
982
- if (number < 10) {
983
- return '0' + number;
984
- }
985
- return String(number);
986
- }
987
987
  /**
988
988
  * Returns YYYY-MM-DD in the local timezone
989
989
  */
@@ -1046,6 +1046,28 @@ const locales = new Map();
1046
1046
  let activeLocale;
1047
1047
  /** @private */
1048
1048
  let activeName;
1049
+ /** @private */
1050
+ function getEnOrdinal(n) {
1051
+ const s = ['th', 'st', 'nd', 'rd'];
1052
+ const v = n % 100;
1053
+ return n + (s[(v - 20) % 10] || s[v] || s[0]);
1054
+ }
1055
+ /** @private */
1056
+ function checkLocale(locale) {
1057
+ if (typeof locale !== 'string') {
1058
+ throw new TypeError(`Invalid locale name: ${locale}`);
1059
+ }
1060
+ return locale.toLowerCase();
1061
+ }
1062
+ /** @private */
1063
+ function getExistingLocale(locale) {
1064
+ const locale1 = checkLocale(locale);
1065
+ const loc = locales.get(locale1);
1066
+ if (!loc) {
1067
+ throw new RangeError(`Locale '${locale}' not found`);
1068
+ }
1069
+ return loc;
1070
+ }
1049
1071
  /**
1050
1072
  * A locale in Hebcal is used for translations/transliterations of
1051
1073
  * holidays. `@hebcal/hdate` supports four locales by default
@@ -1087,13 +1109,11 @@ class Locale {
1087
1109
  * @param data parsed data from a `.po` file.
1088
1110
  */
1089
1111
  static addLocale(locale, data) {
1090
- if (typeof locale !== 'string') {
1091
- throw new TypeError(`Invalid locale name: ${locale}`);
1092
- }
1112
+ locale = checkLocale(locale);
1093
1113
  if (typeof data.contexts !== 'object' || typeof data.contexts[''] !== 'object') {
1094
1114
  throw new TypeError(`Locale '${locale}' invalid compact format`);
1095
1115
  }
1096
- locales.set(locale.toLowerCase(), data.contexts['']);
1116
+ locales.set(locale, data.contexts['']);
1097
1117
  }
1098
1118
  /**
1099
1119
  * Adds a translation to `locale`, replacing any previous translation.
@@ -1102,15 +1122,9 @@ class Locale {
1102
1122
  * @param translation Translation text
1103
1123
  */
1104
1124
  static addTranslation(locale, id, translation) {
1105
- if (typeof locale !== 'string') {
1106
- throw new TypeError(`Invalid locale name: ${locale}`);
1107
- }
1108
- const loc = locales.get(locale.toLowerCase());
1109
- if (!loc) {
1110
- throw new TypeError(`Unknown locale: ${locale}`);
1111
- }
1125
+ const loc = getExistingLocale(locale);
1112
1126
  if (typeof id !== 'string' || id.length === 0) {
1113
- throw new TypeError(`Invalid id: ${id}`);
1127
+ throw new TypeError(`Invalid id string: ${id}`);
1114
1128
  }
1115
1129
  const isArray = Array.isArray(translation);
1116
1130
  if (isArray) {
@@ -1119,7 +1133,7 @@ class Locale {
1119
1133
  throw new TypeError(`Invalid translation array: ${translation}`);
1120
1134
  }
1121
1135
  } else if (typeof translation !== 'string') {
1122
- throw new TypeError(`Invalid translation: ${translation}`);
1136
+ throw new TypeError(`Invalid translation string: ${translation}`);
1123
1137
  }
1124
1138
  loc[id] = isArray ? translation : [translation];
1125
1139
  }
@@ -1129,13 +1143,7 @@ class Locale {
1129
1143
  * @param data parsed data from a `.po` file.
1130
1144
  */
1131
1145
  static addTranslations(locale, data) {
1132
- if (typeof locale !== 'string') {
1133
- throw new TypeError(`Invalid locale name: ${locale}`);
1134
- }
1135
- const loc = locales.get(locale.toLowerCase());
1136
- if (!loc) {
1137
- throw new TypeError(`Unknown locale: ${locale}`);
1138
- }
1146
+ const loc = getExistingLocale(locale);
1139
1147
  if (typeof data.contexts !== 'object' || typeof data.contexts[''] !== 'object') {
1140
1148
  throw new TypeError(`Locale '${locale}' invalid compact format`);
1141
1149
  }
@@ -1149,11 +1157,8 @@ class Locale {
1149
1157
  * @param locale Locale name (i.e: `'he'`, `'fr'`)
1150
1158
  */
1151
1159
  static useLocale(locale) {
1152
- const locale0 = locale.toLowerCase();
1153
- const obj = locales.get(locale0);
1154
- if (!obj) {
1155
- throw new RangeError(`Locale '${locale}' not found`);
1156
- }
1160
+ const locale0 = checkLocale(locale);
1161
+ const obj = getExistingLocale(locale0);
1157
1162
  activeName = alias[locale0] || locale0;
1158
1163
  activeLocale = obj;
1159
1164
  return activeLocale;
@@ -1179,31 +1184,24 @@ class Locale {
1179
1184
  const locale1 = locale === null || locale === void 0 ? void 0 : locale.toLowerCase();
1180
1185
  const locale0 = locale1 || activeName;
1181
1186
  if (!locale0) {
1182
- return this.getEnOrdinal(n);
1187
+ return getEnOrdinal(n);
1183
1188
  }
1184
1189
  switch (locale0) {
1185
1190
  case 'en':
1186
1191
  case 's':
1187
1192
  case 'a':
1188
- case 'ashkenazi':
1189
- case 'ashkenazi_litvish':
1190
- case 'ashkenazi_poylish':
1191
- case 'ashkenazi_standard':
1192
- return this.getEnOrdinal(n);
1193
+ return getEnOrdinal(n);
1193
1194
  case 'es':
1194
1195
  return n + 'º';
1195
1196
  case 'h':
1196
1197
  case 'he':
1197
1198
  case 'he-x-nonikud':
1198
1199
  return String(n);
1199
- default:
1200
- return n + '.';
1201
1200
  }
1202
- }
1203
- static getEnOrdinal(n) {
1204
- const s = ['th', 'st', 'nd', 'rd'];
1205
- const v = n % 100;
1206
- return n + (s[(v - 20) % 10] || s[v] || s[0]);
1201
+ if (locale0.startsWith('ashkenazi')) {
1202
+ return getEnOrdinal(n);
1203
+ }
1204
+ return n + '.';
1207
1205
  }
1208
1206
  /**
1209
1207
  * Removes nekudot from Hebrew string
@@ -1388,7 +1386,7 @@ class HDate {
1388
1386
  * @returns an integer 1-13
1389
1387
  * @example
1390
1388
  * const hd = new HDate(new Date(2008, 10, 13)); // 15 Cheshvan 5769
1391
- * hd.getMonth(); // 2
1389
+ * hd.getTishreiMonth(); // 2
1392
1390
  */
1393
1391
  getTishreiMonth() {
1394
1392
  const nummonths = monthsInYear(this.getFullYear());
@@ -1626,7 +1624,8 @@ class HDate {
1626
1624
  return new HDate(this.abs() + 7 * amount);
1627
1625
  } else if (units === UNITS_YEAR) {
1628
1626
  return new HDate(this.getDate(), this.getMonth(), this.getFullYear() + amount);
1629
- } else if (units === UNITS_MONTH) {
1627
+ } else {
1628
+ // units === UNITS_MONTH
1630
1629
  let hd = new HDate(this);
1631
1630
  const sign = amount > 0 ? 1 : -1;
1632
1631
  amount = Math.abs(amount);
@@ -1634,8 +1633,6 @@ class HDate {
1634
1633
  hd = new HDate(hd.abs() + sign * hd.daysInMonth());
1635
1634
  }
1636
1635
  return hd;
1637
- } else {
1638
- throw new TypeError(`Invalid units '${units}'`);
1639
1636
  }
1640
1637
  }
1641
1638
  /**
@@ -1678,9 +1675,6 @@ class HDate {
1678
1675
  * @param other Hebrew date to compare
1679
1676
  */
1680
1677
  deltaDays(other) {
1681
- if (!HDate.isHDate(other)) {
1682
- throw new TypeError(`Bad argument: ${other}`);
1683
- }
1684
1678
  return this.abs() - other.abs();
1685
1679
  }
1686
1680
  /**
@@ -1692,10 +1686,7 @@ class HDate {
1692
1686
  * hd1.isSameDate(hd2); // true
1693
1687
  */
1694
1688
  isSameDate(other) {
1695
- if (HDate.isHDate(other)) {
1696
- return this.yy === other.yy && this.mm === other.mm && this.dd === other.dd;
1697
- }
1698
- return false;
1689
+ return this.yy === other.yy && this.mm === other.mm && this.dd === other.dd;
1699
1690
  }
1700
1691
  /**
1701
1692
  * Returns a string representation of this Hebrew date using English transliterations
@@ -11693,7 +11684,7 @@ class DailyLearning {
11693
11684
  }
11694
11685
 
11695
11686
  /** DO NOT EDIT THIS AUTO-GENERATED FILE! */
11696
- const version = '5.4.10';
11687
+ const version = '5.4.11';
11697
11688
 
11698
11689
  /* eslint-disable max-len */
11699
11690
  /**