@hebcal/core 5.0.4 → 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/dist/bundle.js CHANGED
@@ -1,4 +1,4 @@
1
- /*! @hebcal/core v5.0.4 */
1
+ /*! @hebcal/core v5.0.5 */
2
2
  var hebcal = (function (exports) {
3
3
  'use strict';
4
4
 
@@ -7602,6 +7602,257 @@ function getTodayIsHe(omer) {
7602
7602
  return str.normalize();
7603
7603
  }
7604
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
+
7605
7856
  /* eslint-disable new-cap */
7606
7857
  /*
7607
7858
  Hebcal - A Jewish Calendar Generator
@@ -7988,7 +8239,9 @@ types['1311'] = types['1221'];
7988
8239
  /* Hebrew year that starts on Saturday, is `complete' (Heshvan and
7989
8240
  * Kislev each have 30 days), and has Passover start on Thursday. */
7990
8241
  types['1721'] = types['170'];
7991
- const sedraCache = new Map();
8242
+ const sedraCache = new QuickLRU({
8243
+ maxSize: 400
8244
+ });
7992
8245
 
7993
8246
  /**
7994
8247
  * @private
@@ -9503,7 +9756,9 @@ const emojiIsraelFlag = {
9503
9756
  emoji: '🇮🇱'
9504
9757
  };
9505
9758
  const chanukahEmoji = '🕎';
9506
- const yearCache = new Map();
9759
+ const yearCache = new QuickLRU({
9760
+ maxSize: 400
9761
+ });
9507
9762
  const KEYCAP_DIGITS = ['0️⃣', '1️⃣', '2️⃣', '3️⃣', '4️⃣', '5️⃣', '6️⃣', '7️⃣', '8️⃣', '9️⃣'];
9508
9763
 
9509
9764
  /**
@@ -9762,7 +10017,7 @@ class DailyLearning {
9762
10017
  }
9763
10018
 
9764
10019
  // DO NOT EDIT THIS AUTO-GENERATED FILE!
9765
- const version = '5.0.4';
10020
+ const version = '5.0.5';
9766
10021
 
9767
10022
  var objectGetOwnPropertyDescriptor = {};
9768
10023
 
@@ -10719,7 +10974,6 @@ function range(start, end) {
10719
10974
  }
10720
10975
  return arr;
10721
10976
  }
10722
- const cache = new Map();
10723
10977
  const NONE = {
10724
10978
  shacharit: false,
10725
10979
  mincha: false,
@@ -10745,12 +10999,7 @@ function tachanun_(hdate, il) {
10745
10999
  */
10746
11000
  function tachanun0(hdate, il, checkNext) {
10747
11001
  const year = hdate.getFullYear();
10748
- const key = `${year}-${il ? 1 : 0}`;
10749
- const cached = cache.get(key);
10750
- const dates = cached || tachanunYear(year, il);
10751
- if (!cached) {
10752
- cache.set(key, dates);
10753
- }
11002
+ const dates = tachanunYear(year, il);
10754
11003
  const abs = hdate.abs();
10755
11004
  if (dates.none.indexOf(abs) > -1) {
10756
11005
  return NONE;