@hebcal/core 5.0.3 → 5.0.5

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/README.md CHANGED
@@ -3122,13 +3122,6 @@ Tachanun is not said at Shacharit on Shabbat, but is at Mincha, usually.
3122
3122
  Gregorian date helper functions.
3123
3123
 
3124
3124
  **Kind**: global variable
3125
- <a name="greg.monthNames"></a>
3126
-
3127
- ### greg.monthNames : <code>Array.&lt;string&gt;</code>
3128
- Long names of the Gregorian months (1='January', 12='December')
3129
-
3130
- **Kind**: static property of [<code>greg</code>](#greg)
3131
- **Read only**: true
3132
3125
  <a name="months"></a>
3133
3126
 
3134
3127
  ## months : <code>enum</code>
package/dist/bundle.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! @hebcal/core v5.0.3 */
1
+ /*! @hebcal/core v5.0.5 */
2
2
  var hebcal = (function (exports) {
3
3
  'use strict';
4
4
 
@@ -28,12 +28,6 @@ const ABS_2SEP1752 = 639785;
28
28
  */
29
29
  exports.greg = void 0;
30
30
  (function (greg) {
31
- /**
32
- * Long names of the Gregorian months (1='January', 12='December')
33
- * @readonly
34
- * @type {string[]}
35
- */
36
- greg.monthNames = ['', 'January', 'February', 'March', 'April', 'May', 'June', 'July', 'August', 'September', 'October', 'November', 'December'];
37
31
  /**
38
32
  * Returns true if the Gregorian year is a leap year
39
33
  * @param {number} year Gregorian year
@@ -7608,6 +7602,257 @@ function getTodayIsHe(omer) {
7608
7602
  return str.normalize();
7609
7603
  }
7610
7604
 
7605
+ class QuickLRU extends Map {
7606
+ #size = 0;
7607
+ #cache = new Map();
7608
+ #oldCache = new Map();
7609
+ #maxSize;
7610
+ #maxAge;
7611
+ #onEviction;
7612
+ constructor() {
7613
+ let options = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : {};
7614
+ super();
7615
+ if (!(options.maxSize && options.maxSize > 0)) {
7616
+ throw new TypeError('`maxSize` must be a number greater than 0');
7617
+ }
7618
+ if (typeof options.maxAge === 'number' && options.maxAge === 0) {
7619
+ throw new TypeError('`maxAge` must be a number greater than 0');
7620
+ }
7621
+ this.#maxSize = options.maxSize;
7622
+ this.#maxAge = options.maxAge || Number.POSITIVE_INFINITY;
7623
+ this.#onEviction = options.onEviction;
7624
+ }
7625
+
7626
+ // For tests.
7627
+ get __oldCache() {
7628
+ return this.#oldCache;
7629
+ }
7630
+ #emitEvictions(cache) {
7631
+ if (typeof this.#onEviction !== 'function') {
7632
+ return;
7633
+ }
7634
+ for (const [key, item] of cache) {
7635
+ this.#onEviction(key, item.value);
7636
+ }
7637
+ }
7638
+ #deleteIfExpired(key, item) {
7639
+ if (typeof item.expiry === 'number' && item.expiry <= Date.now()) {
7640
+ if (typeof this.#onEviction === 'function') {
7641
+ this.#onEviction(key, item.value);
7642
+ }
7643
+ return this.delete(key);
7644
+ }
7645
+ return false;
7646
+ }
7647
+ #getOrDeleteIfExpired(key, item) {
7648
+ const deleted = this.#deleteIfExpired(key, item);
7649
+ if (deleted === false) {
7650
+ return item.value;
7651
+ }
7652
+ }
7653
+ #getItemValue(key, item) {
7654
+ return item.expiry ? this.#getOrDeleteIfExpired(key, item) : item.value;
7655
+ }
7656
+ #peek(key, cache) {
7657
+ const item = cache.get(key);
7658
+ return this.#getItemValue(key, item);
7659
+ }
7660
+ #set(key, value) {
7661
+ this.#cache.set(key, value);
7662
+ this.#size++;
7663
+ if (this.#size >= this.#maxSize) {
7664
+ this.#size = 0;
7665
+ this.#emitEvictions(this.#oldCache);
7666
+ this.#oldCache = this.#cache;
7667
+ this.#cache = new Map();
7668
+ }
7669
+ }
7670
+ #moveToRecent(key, item) {
7671
+ this.#oldCache.delete(key);
7672
+ this.#set(key, item);
7673
+ }
7674
+ *#entriesAscending() {
7675
+ for (const item of this.#oldCache) {
7676
+ const [key, value] = item;
7677
+ if (!this.#cache.has(key)) {
7678
+ const deleted = this.#deleteIfExpired(key, value);
7679
+ if (deleted === false) {
7680
+ yield item;
7681
+ }
7682
+ }
7683
+ }
7684
+ for (const item of this.#cache) {
7685
+ const [key, value] = item;
7686
+ const deleted = this.#deleteIfExpired(key, value);
7687
+ if (deleted === false) {
7688
+ yield item;
7689
+ }
7690
+ }
7691
+ }
7692
+ get(key) {
7693
+ if (this.#cache.has(key)) {
7694
+ const item = this.#cache.get(key);
7695
+ return this.#getItemValue(key, item);
7696
+ }
7697
+ if (this.#oldCache.has(key)) {
7698
+ const item = this.#oldCache.get(key);
7699
+ if (this.#deleteIfExpired(key, item) === false) {
7700
+ this.#moveToRecent(key, item);
7701
+ return item.value;
7702
+ }
7703
+ }
7704
+ }
7705
+ set(key, value) {
7706
+ let {
7707
+ maxAge = this.#maxAge
7708
+ } = arguments.length > 2 && arguments[2] !== undefined ? arguments[2] : {};
7709
+ const expiry = typeof maxAge === 'number' && maxAge !== Number.POSITIVE_INFINITY ? Date.now() + maxAge : undefined;
7710
+ if (this.#cache.has(key)) {
7711
+ this.#cache.set(key, {
7712
+ value,
7713
+ expiry
7714
+ });
7715
+ } else {
7716
+ this.#set(key, {
7717
+ value,
7718
+ expiry
7719
+ });
7720
+ }
7721
+ return this;
7722
+ }
7723
+ has(key) {
7724
+ if (this.#cache.has(key)) {
7725
+ return !this.#deleteIfExpired(key, this.#cache.get(key));
7726
+ }
7727
+ if (this.#oldCache.has(key)) {
7728
+ return !this.#deleteIfExpired(key, this.#oldCache.get(key));
7729
+ }
7730
+ return false;
7731
+ }
7732
+ peek(key) {
7733
+ if (this.#cache.has(key)) {
7734
+ return this.#peek(key, this.#cache);
7735
+ }
7736
+ if (this.#oldCache.has(key)) {
7737
+ return this.#peek(key, this.#oldCache);
7738
+ }
7739
+ }
7740
+ delete(key) {
7741
+ const deleted = this.#cache.delete(key);
7742
+ if (deleted) {
7743
+ this.#size--;
7744
+ }
7745
+ return this.#oldCache.delete(key) || deleted;
7746
+ }
7747
+ clear() {
7748
+ this.#cache.clear();
7749
+ this.#oldCache.clear();
7750
+ this.#size = 0;
7751
+ }
7752
+ resize(newSize) {
7753
+ if (!(newSize && newSize > 0)) {
7754
+ throw new TypeError('`maxSize` must be a number greater than 0');
7755
+ }
7756
+ const items = [...this.#entriesAscending()];
7757
+ const removeCount = items.length - newSize;
7758
+ if (removeCount < 0) {
7759
+ this.#cache = new Map(items);
7760
+ this.#oldCache = new Map();
7761
+ this.#size = items.length;
7762
+ } else {
7763
+ if (removeCount > 0) {
7764
+ this.#emitEvictions(items.slice(0, removeCount));
7765
+ }
7766
+ this.#oldCache = new Map(items.slice(removeCount));
7767
+ this.#cache = new Map();
7768
+ this.#size = 0;
7769
+ }
7770
+ this.#maxSize = newSize;
7771
+ }
7772
+ *keys() {
7773
+ for (const [key] of this) {
7774
+ yield key;
7775
+ }
7776
+ }
7777
+ *values() {
7778
+ for (const [, value] of this) {
7779
+ yield value;
7780
+ }
7781
+ }
7782
+ *[Symbol.iterator]() {
7783
+ for (const item of this.#cache) {
7784
+ const [key, value] = item;
7785
+ const deleted = this.#deleteIfExpired(key, value);
7786
+ if (deleted === false) {
7787
+ yield [key, value.value];
7788
+ }
7789
+ }
7790
+ for (const item of this.#oldCache) {
7791
+ const [key, value] = item;
7792
+ if (!this.#cache.has(key)) {
7793
+ const deleted = this.#deleteIfExpired(key, value);
7794
+ if (deleted === false) {
7795
+ yield [key, value.value];
7796
+ }
7797
+ }
7798
+ }
7799
+ }
7800
+ *entriesDescending() {
7801
+ let items = [...this.#cache];
7802
+ for (let i = items.length - 1; i >= 0; --i) {
7803
+ const item = items[i];
7804
+ const [key, value] = item;
7805
+ const deleted = this.#deleteIfExpired(key, value);
7806
+ if (deleted === false) {
7807
+ yield [key, value.value];
7808
+ }
7809
+ }
7810
+ items = [...this.#oldCache];
7811
+ for (let i = items.length - 1; i >= 0; --i) {
7812
+ const item = items[i];
7813
+ const [key, value] = item;
7814
+ if (!this.#cache.has(key)) {
7815
+ const deleted = this.#deleteIfExpired(key, value);
7816
+ if (deleted === false) {
7817
+ yield [key, value.value];
7818
+ }
7819
+ }
7820
+ }
7821
+ }
7822
+ *entriesAscending() {
7823
+ for (const [key, value] of this.#entriesAscending()) {
7824
+ yield [key, value.value];
7825
+ }
7826
+ }
7827
+ get size() {
7828
+ if (!this.#size) {
7829
+ return this.#oldCache.size;
7830
+ }
7831
+ let oldCacheSize = 0;
7832
+ for (const key of this.#oldCache.keys()) {
7833
+ if (!this.#cache.has(key)) {
7834
+ oldCacheSize++;
7835
+ }
7836
+ }
7837
+ return Math.min(this.#size + oldCacheSize, this.#maxSize);
7838
+ }
7839
+ get maxSize() {
7840
+ return this.#maxSize;
7841
+ }
7842
+ entries() {
7843
+ return this.entriesAscending();
7844
+ }
7845
+ forEach(callbackFunction) {
7846
+ let thisArgument = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : this;
7847
+ for (const [key, value] of this.entriesAscending()) {
7848
+ callbackFunction.call(thisArgument, value, key, this);
7849
+ }
7850
+ }
7851
+ get [Symbol.toStringTag]() {
7852
+ return JSON.stringify([...this.entriesAscending()]);
7853
+ }
7854
+ }
7855
+
7611
7856
  /* eslint-disable new-cap */
7612
7857
  /*
7613
7858
  Hebcal - A Jewish Calendar Generator
@@ -7772,7 +8017,6 @@ class Sedra {
7772
8017
  }
7773
8018
 
7774
8019
  /**
7775
- * @private
7776
8020
  * @return {Object[]}
7777
8021
  */
7778
8022
  getSedraArray() {
@@ -7805,7 +8049,7 @@ class Sedra {
7805
8049
  const weekNum = (saturday - this.firstSaturday) / 7;
7806
8050
  const index = this.theSedraArray[weekNum];
7807
8051
  if (typeof index === 'undefined') {
7808
- const sedra = new Sedra(this.year + 1, this.il);
8052
+ const sedra = getSedra_(this.year + 1, this.il);
7809
8053
  return sedra.lookup(saturday); // must be next year
7810
8054
  }
7811
8055
  if (typeof index === 'string') {
@@ -7995,6 +8239,25 @@ types['1311'] = types['1221'];
7995
8239
  /* Hebrew year that starts on Saturday, is `complete' (Heshvan and
7996
8240
  * Kislev each have 30 days), and has Passover start on Thursday. */
7997
8241
  types['1721'] = types['170'];
8242
+ const sedraCache = new QuickLRU({
8243
+ maxSize: 400
8244
+ });
8245
+
8246
+ /**
8247
+ * @private
8248
+ * @param {number} hyear
8249
+ * @param {boolean} il
8250
+ * @return {Sedra}
8251
+ */
8252
+ function getSedra_(hyear, il) {
8253
+ const cacheKey = `${hyear}-${il ? 1 : 0}`;
8254
+ let sedra = sedraCache.get(cacheKey);
8255
+ if (!sedra) {
8256
+ sedra = new Sedra(hyear, il);
8257
+ sedraCache.set(cacheKey, sedra);
8258
+ }
8259
+ return sedra;
8260
+ }
7998
8261
 
7999
8262
  /**
8000
8263
  * Represents one of 54 weekly Torah portions, always on a Saturday
@@ -9489,28 +9752,13 @@ const KISLEV = months.KISLEV;
9489
9752
  const TEVET = months.TEVET;
9490
9753
  const ADAR_I = months.ADAR_I;
9491
9754
  const ADAR_II = months.ADAR_II;
9492
- const sedraCache = new Map();
9493
-
9494
- /**
9495
- * @private
9496
- * @param {number} hyear
9497
- * @param {boolean} il
9498
- * @return {Sedra}
9499
- */
9500
- function getSedra_(hyear, il) {
9501
- const cacheKey = `${hyear}-${il ? 1 : 0}`;
9502
- let sedra = sedraCache.get(cacheKey);
9503
- if (!sedra) {
9504
- sedra = new Sedra(hyear, il);
9505
- sedraCache.set(cacheKey, sedra);
9506
- }
9507
- return sedra;
9508
- }
9509
9755
  const emojiIsraelFlag = {
9510
9756
  emoji: '🇮🇱'
9511
9757
  };
9512
9758
  const chanukahEmoji = '🕎';
9513
- const yearCache = new Map();
9759
+ const yearCache = new QuickLRU({
9760
+ maxSize: 400
9761
+ });
9514
9762
  const KEYCAP_DIGITS = ['0️⃣', '1️⃣', '2️⃣', '3️⃣', '4️⃣', '5️⃣', '6️⃣', '7️⃣', '8️⃣', '9️⃣'];
9515
9763
 
9516
9764
  /**
@@ -9769,7 +10017,7 @@ class DailyLearning {
9769
10017
  }
9770
10018
 
9771
10019
  // DO NOT EDIT THIS AUTO-GENERATED FILE!
9772
- const version = '5.0.3';
10020
+ const version = '5.0.5';
9773
10021
 
9774
10022
  var objectGetOwnPropertyDescriptor = {};
9775
10023
 
@@ -10726,7 +10974,6 @@ function range(start, end) {
10726
10974
  }
10727
10975
  return arr;
10728
10976
  }
10729
- const cache = new Map();
10730
10977
  const NONE = {
10731
10978
  shacharit: false,
10732
10979
  mincha: false,
@@ -10752,12 +10999,7 @@ function tachanun_(hdate, il) {
10752
10999
  */
10753
11000
  function tachanun0(hdate, il, checkNext) {
10754
11001
  const year = hdate.getFullYear();
10755
- const key = `${year}-${il ? 1 : 0}`;
10756
- const cached = cache.get(key);
10757
- const dates = cached || tachanunYear(year, il);
10758
- if (!cached) {
10759
- cache.set(key, dates);
10760
- }
11002
+ const dates = tachanunYear(year, il);
10761
11003
  const abs = hdate.abs();
10762
11004
  if (dates.none.indexOf(abs) > -1) {
10763
11005
  return NONE;
@@ -11307,8 +11549,6 @@ function observedInIsrael(ev) {
11307
11549
  function observedInDiaspora(ev) {
11308
11550
  return ev.observedInDiaspora();
11309
11551
  }
11310
- const yearArrayCache = new Map();
11311
- const holidaysOnDate = new Map();
11312
11552
 
11313
11553
  /**
11314
11554
  * HebrewCalendar is the main interface to the `@hebcal/core` library.
@@ -11634,15 +11874,10 @@ class HebrewCalendar {
11634
11874
  * @return {Event[]}
11635
11875
  */
11636
11876
  static getHolidaysForYearArray(year, il) {
11637
- const cacheKey = `${year}-${il ? 1 : 0}`;
11638
- let events = yearArrayCache.get(cacheKey);
11639
- if (events) {
11640
- return events;
11641
- }
11642
11877
  const yearMap = getHolidaysForYear_(year);
11643
11878
  const startAbs = HDate.hebrew2abs(year, TISHREI, 1);
11644
11879
  const endAbs = HDate.hebrew2abs(year + 1, TISHREI, 1) - 1;
11645
- events = [];
11880
+ let events = [];
11646
11881
  const myFilter = il ? observedInIsrael : observedInDiaspora;
11647
11882
  for (let absDt = startAbs; absDt <= endAbs; absDt++) {
11648
11883
  const hd = new HDate(absDt);
@@ -11652,7 +11887,6 @@ class HebrewCalendar {
11652
11887
  events = events.concat(filtered);
11653
11888
  }
11654
11889
  }
11655
- yearArrayCache.set(cacheKey, events);
11656
11890
  return events;
11657
11891
  }
11658
11892
 
@@ -11665,20 +11899,14 @@ class HebrewCalendar {
11665
11899
  static getHolidaysOnDate(date, il) {
11666
11900
  const hd = HDate.isHDate(date) ? date : new HDate(date);
11667
11901
  const hdStr = hd.toString();
11668
- const cacheKey = hdStr + '/' + (typeof il === 'undefined' ? 2 : il ? 1 : 0);
11669
- if (holidaysOnDate.has(cacheKey)) {
11670
- return holidaysOnDate.get(cacheKey);
11671
- }
11672
11902
  const yearMap = getHolidaysForYear_(hd.getFullYear());
11673
11903
  const events = yearMap.get(hdStr);
11674
11904
  // if il isn't a boolean return both diaspora + IL for day
11675
11905
  if (typeof il === 'undefined' || typeof events === 'undefined') {
11676
- holidaysOnDate.set(cacheKey, events);
11677
11906
  return events;
11678
11907
  }
11679
11908
  const myFilter = il ? observedInIsrael : observedInDiaspora;
11680
11909
  const filtered = events.filter(myFilter);
11681
- holidaysOnDate.set(cacheKey, filtered);
11682
11910
  return filtered;
11683
11911
  }
11684
11912