@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/index.mjs CHANGED
@@ -1,4 +1,4 @@
1
- /*! @hebcal/core v5.4.10 */
1
+ /*! @hebcal/core v5.4.11 */
2
2
  /* eslint-disable @typescript-eslint/no-namespace, no-inner-declarations */
3
3
  /** @private */
4
4
  const lengths = [0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31];
@@ -143,15 +143,15 @@ greg.isLeapYear = isGregLeapYear;
143
143
  */
144
144
  const NISAN$4 = 1;
145
145
  const IYYAR$1 = 2;
146
- // const SIVAN = 3;
146
+ const SIVAN$1 = 3;
147
147
  const TAMUZ$1 = 4;
148
- // const AV = 5;
148
+ const AV$1 = 5;
149
149
  const ELUL$1 = 6;
150
150
  const TISHREI$3 = 7;
151
151
  const CHESHVAN$1 = 8;
152
152
  const KISLEV$2 = 9;
153
153
  const TEVET$2 = 10;
154
- // const SHVAT = 11;
154
+ const SHVAT$1 = 11;
155
155
  const ADAR_I$2 = 12;
156
156
  const ADAR_II$2 = 13;
157
157
  /**
@@ -161,31 +161,31 @@ const ADAR_II$2 = 13;
161
161
  */
162
162
  const months = {
163
163
  /** Nissan / ניסן */
164
- NISAN: 1,
164
+ NISAN: NISAN$4,
165
165
  /** Iyyar / אייר */
166
- IYYAR: 2,
166
+ IYYAR: IYYAR$1,
167
167
  /** Sivan / סיון */
168
- SIVAN: 3,
168
+ SIVAN: SIVAN$1,
169
169
  /** Tamuz (sometimes Tammuz) / תמוז */
170
- TAMUZ: 4,
170
+ TAMUZ: TAMUZ$1,
171
171
  /** Av / אב */
172
- AV: 5,
172
+ AV: AV$1,
173
173
  /** Elul / אלול */
174
- ELUL: 6,
174
+ ELUL: ELUL$1,
175
175
  /** Tishrei / תִּשְׁרֵי */
176
- TISHREI: 7,
176
+ TISHREI: TISHREI$3,
177
177
  /** Cheshvan / חשון */
178
- CHESHVAN: 8,
178
+ CHESHVAN: CHESHVAN$1,
179
179
  /** Kislev / כסלו */
180
- KISLEV: 9,
180
+ KISLEV: KISLEV$2,
181
181
  /** Tevet / טבת */
182
- TEVET: 10,
182
+ TEVET: TEVET$2,
183
183
  /** Sh'vat / שבט */
184
- SHVAT: 11,
184
+ SHVAT: SHVAT$1,
185
185
  /** Adar or Adar Rishon / אדר */
186
- ADAR_I: 12,
186
+ ADAR_I: ADAR_I$2,
187
187
  /** Adar Sheini (only on leap years) / אדר ב׳ */
188
- ADAR_II: 13,
188
+ ADAR_II: ADAR_II$2,
189
189
  };
190
190
  const monthNames0 = [
191
191
  '',
@@ -445,73 +445,73 @@ function monthFromName(monthName) {
445
445
  if (c[1] === 'o') {
446
446
  break; /* this catches "november" */
447
447
  }
448
- return months.NISAN;
448
+ return NISAN$4;
449
449
  case 'i':
450
- return months.IYYAR;
450
+ return IYYAR$1;
451
451
  case 'e':
452
- return months.ELUL;
452
+ return ELUL$1;
453
453
  case 'c':
454
454
  case 'ח':
455
- return months.CHESHVAN;
455
+ return CHESHVAN$1;
456
456
  case 'k':
457
457
  case 'כ':
458
- return months.KISLEV;
458
+ return KISLEV$2;
459
459
  case 's':
460
460
  switch (c[1]) {
461
461
  case 'i':
462
- return months.SIVAN;
462
+ return SIVAN$1;
463
463
  case 'h':
464
- return months.SHVAT;
464
+ return SHVAT$1;
465
465
  }
466
466
  break;
467
467
  case 't':
468
468
  switch (c[1]) {
469
469
  case 'a':
470
- return months.TAMUZ;
470
+ return TAMUZ$1;
471
471
  case 'i':
472
- return months.TISHREI;
472
+ return TISHREI$3;
473
473
  case 'e':
474
- return months.TEVET;
474
+ return TEVET$2;
475
475
  }
476
476
  break;
477
477
  case 'a':
478
478
  switch (c[1]) {
479
479
  case 'v':
480
- return months.AV;
480
+ return AV$1;
481
481
  case 'd':
482
482
  if (/(1|[^i]i|a|א)$/i.test(monthName)) {
483
- return months.ADAR_I;
483
+ return ADAR_I$2;
484
484
  }
485
- return months.ADAR_II; // else assume sheini
485
+ return ADAR_II$2; // else assume sheini
486
486
  }
487
487
  break;
488
488
  case 'ס':
489
- return months.SIVAN;
489
+ return SIVAN$1;
490
490
  case 'ט':
491
- return months.TEVET;
491
+ return TEVET$2;
492
492
  case 'ש':
493
- return months.SHVAT;
493
+ return SHVAT$1;
494
494
  case 'א':
495
495
  switch (c[1]) {
496
496
  case 'ב':
497
- return months.AV;
497
+ return AV$1;
498
498
  case 'ד':
499
499
  if (/(1|[^i]i|a|א)$/i.test(monthName)) {
500
- return months.ADAR_I;
500
+ return ADAR_I$2;
501
501
  }
502
- return months.ADAR_II; // else assume sheini
502
+ return ADAR_II$2; // else assume sheini
503
503
  case 'י':
504
- return months.IYYAR;
504
+ return IYYAR$1;
505
505
  case 'ל':
506
- return months.ELUL;
506
+ return ELUL$1;
507
507
  }
508
508
  break;
509
509
  case 'ת':
510
510
  switch (c[1]) {
511
511
  case 'מ':
512
- return months.TAMUZ;
512
+ return TAMUZ$1;
513
513
  case 'ש':
514
- return months.TISHREI;
514
+ return TISHREI$3;
515
515
  }
516
516
  break;
517
517
  }
@@ -543,15 +543,13 @@ function toSimpleHebrewDate(obj) {
543
543
  if (isSimpleHebrewDate$1(obj)) {
544
544
  return obj;
545
545
  }
546
- else if (typeof obj === 'number') {
547
- return abs2hebrew(obj);
548
- }
549
546
  else if (isDate(obj)) {
550
547
  const abs = greg2abs(obj);
551
548
  return abs2hebrew(abs);
552
549
  }
553
550
  else {
554
- throw new TypeError(`Argument not a Date: ${obj}`);
551
+ // typeof obj === 'number'
552
+ return abs2hebrew(obj);
555
553
  }
556
554
  }
557
555
  function getYahrzeitHD(hyear, date) {
@@ -698,8 +696,8 @@ function num2digits(num) {
698
696
  function gematriya(num) {
699
697
  const num0 = num;
700
698
  const num1 = parseInt(num0, 10);
701
- if (!num1) {
702
- throw new TypeError(`invalid parameter to gematriya ${num}`);
699
+ if (!num1 || num1 < 0) {
700
+ throw new TypeError(`invalid gematriya number: ${num}`);
703
701
  }
704
702
  let str = '';
705
703
  const thousands = Math.floor(num1 / 1000);
@@ -1004,6 +1002,38 @@ function molad(year, month) {
1004
1002
  };
1005
1003
  }
1006
1004
 
1005
+ /**
1006
+ * Formats a number with leading zeros so the resulting string is 4 digits long.
1007
+ * Similar to `string.padStart(4, '0')` but will also format
1008
+ * negative numbers similar to how the JavaScript date formats
1009
+ * negative year numbers (e.g. `-37` is formatted as `-000037`).
1010
+ */
1011
+ function pad4(num) {
1012
+ if (num < 0) {
1013
+ return '-00' + pad4(-num);
1014
+ }
1015
+ else if (num < 10) {
1016
+ return '000' + num;
1017
+ }
1018
+ else if (num < 100) {
1019
+ return '00' + num;
1020
+ }
1021
+ else if (num < 1000) {
1022
+ return '0' + num;
1023
+ }
1024
+ return String(num);
1025
+ }
1026
+ /**
1027
+ * Formats a number with leading zeros so the resulting string is 2 digits long.
1028
+ * Similar to `string.padStart(2, '0')`.
1029
+ */
1030
+ function pad2(num) {
1031
+ if (num >= 0 && num < 10) {
1032
+ return '0' + num;
1033
+ }
1034
+ return String(num);
1035
+ }
1036
+
1007
1037
  const _formatters = new Map();
1008
1038
  /**
1009
1039
  * @private
@@ -1053,37 +1083,6 @@ function getTimezoneOffset(tzid, date) {
1053
1083
  const diffMs = new Date(utcStr).getTime() - new Date(localStr).getTime();
1054
1084
  return Math.ceil(diffMs / 1000 / 60);
1055
1085
  }
1056
- /**
1057
- * Formats a number with leading zeros so the resulting string is 4 digits long.
1058
- * Similar to `string.padStart(4, '0')` but will also format
1059
- * negative numbers similar to how the JavaScript date formats
1060
- * negative year numbers (e.g. `-37` is formatted as `-000037`).
1061
- */
1062
- function pad4(number) {
1063
- if (number < 0) {
1064
- return '-00' + pad4(-number);
1065
- }
1066
- else if (number < 10) {
1067
- return '000' + number;
1068
- }
1069
- else if (number < 100) {
1070
- return '00' + number;
1071
- }
1072
- else if (number < 1000) {
1073
- return '0' + number;
1074
- }
1075
- return String(number);
1076
- }
1077
- /**
1078
- * Formats a number with leading zeros so the resulting string is 2 digits long.
1079
- * Similar to `string.padStart(2, '0')`.
1080
- */
1081
- function pad2(number) {
1082
- if (number < 10) {
1083
- return '0' + number;
1084
- }
1085
- return String(number);
1086
- }
1087
1086
  /**
1088
1087
  * Returns YYYY-MM-DD in the local timezone
1089
1088
  */
@@ -1115,6 +1114,28 @@ const locales = new Map();
1115
1114
  let activeLocale;
1116
1115
  /** @private */
1117
1116
  let activeName;
1117
+ /** @private */
1118
+ function getEnOrdinal(n) {
1119
+ const s = ['th', 'st', 'nd', 'rd'];
1120
+ const v = n % 100;
1121
+ return n + (s[(v - 20) % 10] || s[v] || s[0]);
1122
+ }
1123
+ /** @private */
1124
+ function checkLocale(locale) {
1125
+ if (typeof locale !== 'string') {
1126
+ throw new TypeError(`Invalid locale name: ${locale}`);
1127
+ }
1128
+ return locale.toLowerCase();
1129
+ }
1130
+ /** @private */
1131
+ function getExistingLocale(locale) {
1132
+ const locale1 = checkLocale(locale);
1133
+ const loc = locales.get(locale1);
1134
+ if (!loc) {
1135
+ throw new RangeError(`Locale '${locale}' not found`);
1136
+ }
1137
+ return loc;
1138
+ }
1118
1139
  /**
1119
1140
  * A locale in Hebcal is used for translations/transliterations of
1120
1141
  * holidays. `@hebcal/hdate` supports four locales by default
@@ -1157,14 +1178,12 @@ class Locale {
1157
1178
  * @param data parsed data from a `.po` file.
1158
1179
  */
1159
1180
  static addLocale(locale, data) {
1160
- if (typeof locale !== 'string') {
1161
- throw new TypeError(`Invalid locale name: ${locale}`);
1162
- }
1181
+ locale = checkLocale(locale);
1163
1182
  if (typeof data.contexts !== 'object' ||
1164
1183
  typeof data.contexts[''] !== 'object') {
1165
1184
  throw new TypeError(`Locale '${locale}' invalid compact format`);
1166
1185
  }
1167
- locales.set(locale.toLowerCase(), data.contexts['']);
1186
+ locales.set(locale, data.contexts['']);
1168
1187
  }
1169
1188
  /**
1170
1189
  * Adds a translation to `locale`, replacing any previous translation.
@@ -1173,15 +1192,9 @@ class Locale {
1173
1192
  * @param translation Translation text
1174
1193
  */
1175
1194
  static addTranslation(locale, id, translation) {
1176
- if (typeof locale !== 'string') {
1177
- throw new TypeError(`Invalid locale name: ${locale}`);
1178
- }
1179
- const loc = locales.get(locale.toLowerCase());
1180
- if (!loc) {
1181
- throw new TypeError(`Unknown locale: ${locale}`);
1182
- }
1195
+ const loc = getExistingLocale(locale);
1183
1196
  if (typeof id !== 'string' || id.length === 0) {
1184
- throw new TypeError(`Invalid id: ${id}`);
1197
+ throw new TypeError(`Invalid id string: ${id}`);
1185
1198
  }
1186
1199
  const isArray = Array.isArray(translation);
1187
1200
  if (isArray) {
@@ -1191,7 +1204,7 @@ class Locale {
1191
1204
  }
1192
1205
  }
1193
1206
  else if (typeof translation !== 'string') {
1194
- throw new TypeError(`Invalid translation: ${translation}`);
1207
+ throw new TypeError(`Invalid translation string: ${translation}`);
1195
1208
  }
1196
1209
  loc[id] = isArray ? translation : [translation];
1197
1210
  }
@@ -1201,13 +1214,7 @@ class Locale {
1201
1214
  * @param data parsed data from a `.po` file.
1202
1215
  */
1203
1216
  static addTranslations(locale, data) {
1204
- if (typeof locale !== 'string') {
1205
- throw new TypeError(`Invalid locale name: ${locale}`);
1206
- }
1207
- const loc = locales.get(locale.toLowerCase());
1208
- if (!loc) {
1209
- throw new TypeError(`Unknown locale: ${locale}`);
1210
- }
1217
+ const loc = getExistingLocale(locale);
1211
1218
  if (typeof data.contexts !== 'object' ||
1212
1219
  typeof data.contexts[''] !== 'object') {
1213
1220
  throw new TypeError(`Locale '${locale}' invalid compact format`);
@@ -1222,11 +1229,8 @@ class Locale {
1222
1229
  * @param locale Locale name (i.e: `'he'`, `'fr'`)
1223
1230
  */
1224
1231
  static useLocale(locale) {
1225
- const locale0 = locale.toLowerCase();
1226
- const obj = locales.get(locale0);
1227
- if (!obj) {
1228
- throw new RangeError(`Locale '${locale}' not found`);
1229
- }
1232
+ const locale0 = checkLocale(locale);
1233
+ const obj = getExistingLocale(locale0);
1230
1234
  activeName = alias[locale0] || locale0;
1231
1235
  activeLocale = obj;
1232
1236
  return activeLocale;
@@ -1252,31 +1256,24 @@ class Locale {
1252
1256
  const locale1 = locale === null || locale === void 0 ? void 0 : locale.toLowerCase();
1253
1257
  const locale0 = locale1 || activeName;
1254
1258
  if (!locale0) {
1255
- return this.getEnOrdinal(n);
1259
+ return getEnOrdinal(n);
1256
1260
  }
1257
1261
  switch (locale0) {
1258
1262
  case 'en':
1259
1263
  case 's':
1260
1264
  case 'a':
1261
- case 'ashkenazi':
1262
- case 'ashkenazi_litvish':
1263
- case 'ashkenazi_poylish':
1264
- case 'ashkenazi_standard':
1265
- return this.getEnOrdinal(n);
1265
+ return getEnOrdinal(n);
1266
1266
  case 'es':
1267
1267
  return n + 'º';
1268
1268
  case 'h':
1269
1269
  case 'he':
1270
1270
  case 'he-x-nonikud':
1271
1271
  return String(n);
1272
- default:
1273
- return n + '.';
1274
1272
  }
1275
- }
1276
- static getEnOrdinal(n) {
1277
- const s = ['th', 'st', 'nd', 'rd'];
1278
- const v = n % 100;
1279
- return n + (s[(v - 20) % 10] || s[v] || s[0]);
1273
+ if (locale0.startsWith('ashkenazi')) {
1274
+ return getEnOrdinal(n);
1275
+ }
1276
+ return n + '.';
1280
1277
  }
1281
1278
  /**
1282
1279
  * Removes nekudot from Hebrew string
@@ -1466,7 +1463,7 @@ class HDate {
1466
1463
  * @returns an integer 1-13
1467
1464
  * @example
1468
1465
  * const hd = new HDate(new Date(2008, 10, 13)); // 15 Cheshvan 5769
1469
- * hd.getMonth(); // 2
1466
+ * hd.getTishreiMonth(); // 2
1470
1467
  */
1471
1468
  getTishreiMonth() {
1472
1469
  const nummonths = monthsInYear(this.getFullYear());
@@ -1706,7 +1703,8 @@ class HDate {
1706
1703
  else if (units === UNITS_YEAR) {
1707
1704
  return new HDate(this.getDate(), this.getMonth(), this.getFullYear() + amount);
1708
1705
  }
1709
- else if (units === UNITS_MONTH) {
1706
+ else {
1707
+ // units === UNITS_MONTH
1710
1708
  let hd = new HDate(this);
1711
1709
  const sign = amount > 0 ? 1 : -1;
1712
1710
  amount = Math.abs(amount);
@@ -1715,9 +1713,6 @@ class HDate {
1715
1713
  }
1716
1714
  return hd;
1717
1715
  }
1718
- else {
1719
- throw new TypeError(`Invalid units '${units}'`);
1720
- }
1721
1716
  }
1722
1717
  /**
1723
1718
  * Returns a cloned `HDate` object with a specified amount of time subracted
@@ -1758,9 +1753,6 @@ class HDate {
1758
1753
  * @param other Hebrew date to compare
1759
1754
  */
1760
1755
  deltaDays(other) {
1761
- if (!HDate.isHDate(other)) {
1762
- throw new TypeError(`Bad argument: ${other}`);
1763
- }
1764
1756
  return this.abs() - other.abs();
1765
1757
  }
1766
1758
  /**
@@ -1772,10 +1764,7 @@ class HDate {
1772
1764
  * hd1.isSameDate(hd2); // true
1773
1765
  */
1774
1766
  isSameDate(other) {
1775
- if (HDate.isHDate(other)) {
1776
- return (this.yy === other.yy && this.mm === other.mm && this.dd === other.dd);
1777
- }
1778
- return false;
1767
+ return this.yy === other.yy && this.mm === other.mm && this.dd === other.dd;
1779
1768
  }
1780
1769
  /**
1781
1770
  * Returns a string representation of this Hebrew date using English transliterations
@@ -10337,7 +10326,7 @@ class DailyLearning {
10337
10326
  }
10338
10327
 
10339
10328
  /** DO NOT EDIT THIS AUTO-GENERATED FILE! */
10340
- const version = '5.4.10';
10329
+ const version = '5.4.11';
10341
10330
 
10342
10331
  /* eslint-disable max-len */
10343
10332
  /**