44 */ 
55Object . defineProperty ( exports ,  "__esModule" ,  {  value : true  } ) ; 
66exports . LRUCache  =  void  0 ; 
7- const  defaultPerf  =  ( typeof  performance  ===  'object'  && 
7+ const  perf  =  typeof  performance  ===  'object'  && 
88    performance  && 
9-     typeof  performance . now  ===  'function' )  ? 
10-     performance 
9+     typeof  performance . now  ===  'function' 
10+     ?  performance 
1111    : Date ; 
1212const  warned  =  new  Set ( ) ; 
1313/* c8 ignore start */ 
14- const  PROCESS  =  ( typeof  process  ===  'object'  &&  ! ! process  ?
15-     process 
16-     : { } ) ; 
14+ const  PROCESS  =  ( typeof  process  ===  'object'  &&  ! ! process  ? process  : { } ) ; 
1715/* c8 ignore start */ 
1816const  emitWarning  =  ( msg ,  type ,  code ,  fn )  =>  { 
19-     typeof  PROCESS . emitWarning  ===  'function'  ? 
20-         PROCESS . emitWarning ( msg ,  type ,  code ,  fn ) 
17+     typeof  PROCESS . emitWarning  ===  'function' 
18+         ?  PROCESS . emitWarning ( msg ,  type ,  code ,  fn ) 
2119        : console . error ( `[${ code } ${ type } ${ msg }  ) ; 
2220} ; 
2321let  AC  =  globalThis . AbortController ; 
@@ -81,11 +79,16 @@ const isPosInt = (n) => n && n === Math.floor(n) && n > 0 && isFinite(n);
8179// zeroes at init time is brutal when you get that big. 
8280// But why not be complete? 
8381// Maybe in the future, these limits will have expanded. 
84- const  getUintArray  =  ( max )  =>  ! isPosInt ( max )  ? null 
85-     : max  <=  Math . pow ( 2 ,  8 )  ? Uint8Array 
86-         : max  <=  Math . pow ( 2 ,  16 )  ? Uint16Array 
87-             : max  <=  Math . pow ( 2 ,  32 )  ? Uint32Array 
88-                 : max  <=  Number . MAX_SAFE_INTEGER  ? ZeroArray 
82+ const  getUintArray  =  ( max )  =>  ! isPosInt ( max ) 
83+     ? null 
84+     : max  <=  Math . pow ( 2 ,  8 ) 
85+         ? Uint8Array 
86+         : max  <=  Math . pow ( 2 ,  16 ) 
87+             ? Uint16Array 
88+             : max  <=  Math . pow ( 2 ,  32 ) 
89+                 ? Uint32Array 
90+                 : max  <=  Number . MAX_SAFE_INTEGER 
91+                     ? ZeroArray 
8992                    : null ; 
9093/* c8 ignore stop */ 
9194class  ZeroArray  extends  Array  { 
@@ -144,17 +147,9 @@ class LRUCache {
144147    #max; 
145148    #maxSize; 
146149    #dispose; 
147-     #onInsert; 
148150    #disposeAfter; 
149151    #fetchMethod; 
150152    #memoMethod; 
151-     #perf; 
152-     /** 
153-      * {@link LRUCache.OptionsBase.perf } 
154-      */ 
155-     get  perf ( )  { 
156-         return  this . #perf; 
157-     } 
158153    /** 
159154     * {@link LRUCache.OptionsBase.ttl } 
160155     */ 
@@ -233,7 +228,6 @@ class LRUCache {
233228    #hasDispose; 
234229    #hasFetchMethod; 
235230    #hasDisposeAfter; 
236-     #hasOnInsert; 
237231    /** 
238232     * Do not call this method unless you need to inspect the 
239233     * inner workings of the cache.  If anything returned by this 
@@ -310,26 +304,14 @@ class LRUCache {
310304    get  dispose ( )  { 
311305        return  this . #dispose; 
312306    } 
313-     /** 
314-      * {@link LRUCache.OptionsBase.onInsert } (read-only) 
315-      */ 
316-     get  onInsert ( )  { 
317-         return  this . #onInsert; 
318-     } 
319307    /** 
320308     * {@link LRUCache.OptionsBase.disposeAfter } (read-only) 
321309     */ 
322310    get  disposeAfter ( )  { 
323311        return  this . #disposeAfter; 
324312    } 
325313    constructor ( options )  { 
326-         const  {  max =  0 ,  ttl,  ttlResolution =  1 ,  ttlAutopurge,  updateAgeOnGet,  updateAgeOnHas,  allowStale,  dispose,  onInsert,  disposeAfter,  noDisposeOnSet,  noUpdateTTL,  maxSize =  0 ,  maxEntrySize =  0 ,  sizeCalculation,  fetchMethod,  memoMethod,  noDeleteOnFetchRejection,  noDeleteOnStaleGet,  allowStaleOnFetchRejection,  allowStaleOnFetchAbort,  ignoreFetchAbort,  perf,  }  =  options ; 
327-         if  ( perf  !==  undefined )  { 
328-             if  ( typeof  perf ?. now  !==  'function' )  { 
329-                 throw  new  TypeError ( 'perf option must have a now() method if specified' ) ; 
330-             } 
331-         } 
332-         this . #perf =  perf  ??  defaultPerf ; 
314+         const  {  max =  0 ,  ttl,  ttlResolution =  1 ,  ttlAutopurge,  updateAgeOnGet,  updateAgeOnHas,  allowStale,  dispose,  disposeAfter,  noDisposeOnSet,  noUpdateTTL,  maxSize =  0 ,  maxEntrySize =  0 ,  sizeCalculation,  fetchMethod,  memoMethod,  noDeleteOnFetchRejection,  noDeleteOnStaleGet,  allowStaleOnFetchRejection,  allowStaleOnFetchAbort,  ignoreFetchAbort,  }  =  options ; 
333315        if  ( max  !==  0  &&  ! isPosInt ( max ) )  { 
334316            throw  new  TypeError ( 'max option must be a nonnegative integer' ) ; 
335317        } 
@@ -373,9 +355,6 @@ class LRUCache {
373355        if  ( typeof  dispose  ===  'function' )  { 
374356            this . #dispose =  dispose ; 
375357        } 
376-         if  ( typeof  onInsert  ===  'function' )  { 
377-             this . #onInsert =  onInsert ; 
378-         } 
379358        if  ( typeof  disposeAfter  ===  'function' )  { 
380359            this . #disposeAfter =  disposeAfter ; 
381360            this . #disposed =  [ ] ; 
@@ -385,7 +364,6 @@ class LRUCache {
385364            this . #disposed =  undefined ; 
386365        } 
387366        this . #hasDispose =  ! ! this . #dispose; 
388-         this . #hasOnInsert =  ! ! this . #onInsert; 
389367        this . #hasDisposeAfter =  ! ! this . #disposeAfter; 
390368        this . noDisposeOnSet  =  ! ! noDisposeOnSet ; 
391369        this . noUpdateTTL  =  ! ! noUpdateTTL ; 
@@ -410,8 +388,8 @@ class LRUCache {
410388        this . updateAgeOnGet  =  ! ! updateAgeOnGet ; 
411389        this . updateAgeOnHas  =  ! ! updateAgeOnHas ; 
412390        this . ttlResolution  = 
413-             isPosInt ( ttlResolution )  ||  ttlResolution  ===  0  ? 
414-                 ttlResolution 
391+             isPosInt ( ttlResolution )  ||  ttlResolution  ===  0 
392+                 ?  ttlResolution 
415393                : 1 ; 
416394        this . ttlAutopurge  =  ! ! ttlAutopurge ; 
417395        this . ttl  =  ttl  ||  0 ; 
@@ -447,7 +425,7 @@ class LRUCache {
447425        const  starts  =  new  ZeroArray ( this . #max) ; 
448426        this . #ttls =  ttls ; 
449427        this . #starts =  starts ; 
450-         this . #setItemTTL =  ( index ,  ttl ,  start  =  this . # perf. now ( ) )  =>  { 
428+         this . #setItemTTL =  ( index ,  ttl ,  start  =  perf . now ( ) )  =>  { 
451429            starts [ index ]  =  ttl  !==  0  ? start  : 0 ; 
452430            ttls [ index ]  =  ttl ; 
453431            if  ( ttl  !==  0  &&  this . ttlAutopurge )  { 
@@ -465,7 +443,7 @@ class LRUCache {
465443            } 
466444        } ; 
467445        this . #updateItemAge =  index  =>  { 
468-             starts [ index ]  =  ttls [ index ]  !==  0  ? this . # perf. now ( )  : 0 ; 
446+             starts [ index ]  =  ttls [ index ]  !==  0  ? perf . now ( )  : 0 ; 
469447        } ; 
470448        this . #statusTTL =  ( status ,  index )  =>  { 
471449            if  ( ttls [ index ] )  { 
@@ -485,7 +463,7 @@ class LRUCache {
485463        // that costly call repeatedly. 
486464        let  cachedNow  =  0 ; 
487465        const  getNow  =  ( )  =>  { 
488-             const  n  =  this . # perf. now ( ) ; 
466+             const  n  =  perf . now ( ) ; 
489467            if  ( this . ttlResolution  >  0 )  { 
490468                cachedNow  =  n ; 
491469                const  t  =  setTimeout ( ( )  =>  ( cachedNow  =  0 ) ,  this . ttlResolution ) ; 
@@ -722,7 +700,9 @@ class LRUCache {
722700    find ( fn ,  getOptions  =  { } )  { 
723701        for  ( const  i  of  this . #indexes( ) )  { 
724702            const  v  =  this . #valList[ i ] ; 
725-             const  value  =  this . #isBackgroundFetch( v )  ? v . __staleWhileFetching  : v ; 
703+             const  value  =  this . #isBackgroundFetch( v ) 
704+                 ? v . __staleWhileFetching 
705+                 : v ; 
726706            if  ( value  ===  undefined ) 
727707                continue ; 
728708            if  ( fn ( value ,  this . #keyList[ i ] ,  this ) )  { 
@@ -744,7 +724,9 @@ class LRUCache {
744724    forEach ( fn ,  thisp  =  this )  { 
745725        for  ( const  i  of  this . #indexes( ) )  { 
746726            const  v  =  this . #valList[ i ] ; 
747-             const  value  =  this . #isBackgroundFetch( v )  ? v . __staleWhileFetching  : v ; 
727+             const  value  =  this . #isBackgroundFetch( v ) 
728+                 ? v . __staleWhileFetching 
729+                 : v ; 
748730            if  ( value  ===  undefined ) 
749731                continue ; 
750732            fn . call ( thisp ,  value ,  this . #keyList[ i ] ,  this ) ; 
@@ -757,7 +739,9 @@ class LRUCache {
757739    rforEach ( fn ,  thisp  =  this )  { 
758740        for  ( const  i  of  this . #rindexes( ) )  { 
759741            const  v  =  this . #valList[ i ] ; 
760-             const  value  =  this . #isBackgroundFetch( v )  ? v . __staleWhileFetching  : v ; 
742+             const  value  =  this . #isBackgroundFetch( v ) 
743+                 ? v . __staleWhileFetching 
744+                 : v ; 
761745            if  ( value  ===  undefined ) 
762746                continue ; 
763747            fn . call ( thisp ,  value ,  this . #keyList[ i ] ,  this ) ; 
@@ -794,18 +778,17 @@ class LRUCache {
794778        if  ( i  ===  undefined ) 
795779            return  undefined ; 
796780        const  v  =  this . #valList[ i ] ; 
797-         /* c8 ignore start -  this isn't tested for the info function, 
798-          * but it's the same logic as found in other places. */  
799-         const   value   =   this . #isBackgroundFetch ( v )  ?  v . __staleWhileFetching  : v ; 
781+         const   value   =   this . #isBackgroundFetch ( v ) 
782+             ?  v . __staleWhileFetching 
783+              : v ; 
800784        if  ( value  ===  undefined ) 
801785            return  undefined ; 
802-         /* c8 ignore end */ 
803786        const  entry  =  {  value } ; 
804787        if  ( this . #ttls &&  this . #starts)  { 
805788            const  ttl  =  this . #ttls[ i ] ; 
806789            const  start  =  this . #starts[ i ] ; 
807790            if  ( ttl  &&  start )  { 
808-                 const  remain  =  ttl  -  ( this . # perf. now ( )  -  start ) ; 
791+                 const  remain  =  ttl  -  ( perf . now ( )  -  start ) ; 
809792                entry . ttl  =  remain ; 
810793                entry . start  =  Date . now ( ) ; 
811794            } 
@@ -817,7 +800,7 @@ class LRUCache {
817800    } 
818801    /** 
819802     * Return an array of [key, {@link  LRUCache.Entry}] tuples which can be 
820-      * passed to {@link  LRUCache #load}. 
803+      * passed to {@link  LRLUCache #load}. 
821804     * 
822805     * The `start` fields are calculated relative to a portable `Date.now()` 
823806     * timestamp, even if `performance.now()` is available. 
@@ -833,15 +816,17 @@ class LRUCache {
833816        for  ( const  i  of  this . #indexes( {  allowStale : true  } ) )  { 
834817            const  key  =  this . #keyList[ i ] ; 
835818            const  v  =  this . #valList[ i ] ; 
836-             const  value  =  this . #isBackgroundFetch( v )  ? v . __staleWhileFetching  : v ; 
819+             const  value  =  this . #isBackgroundFetch( v ) 
820+                 ? v . __staleWhileFetching 
821+                 : v ; 
837822            if  ( value  ===  undefined  ||  key  ===  undefined ) 
838823                continue ; 
839824            const  entry  =  {  value } ; 
840825            if  ( this . #ttls &&  this . #starts)  { 
841826                entry . ttl  =  this . #ttls[ i ] ; 
842827                // always dump the start relative to a portable timestamp 
843828                // it's ok for this to be a bit slow, it's a rare operation. 
844-                 const  age  =  this . # perf. now ( )  -  this . #starts[ i ] ; 
829+                 const  age  =  perf . now ( )  -  this . #starts[ i ] ; 
845830                entry . start  =  Math . floor ( Date . now ( )  -  age ) ; 
846831            } 
847832            if  ( this . #sizes)  { 
@@ -871,7 +856,7 @@ class LRUCache {
871856                // 
872857                // it's ok for this to be a bit slow, it's a rare operation. 
873858                const  age  =  Date . now ( )  -  entry . start ; 
874-                 entry . start  =  this . # perf. now ( )  -  age ; 
859+                 entry . start  =  perf . now ( )  -  age ; 
875860            } 
876861            this . set ( key ,  entry . value ,  entry ) ; 
877862        } 
@@ -928,9 +913,12 @@ class LRUCache {
928913        let  index  =  this . #size ===  0  ? undefined  : this . #keyMap. get ( k ) ; 
929914        if  ( index  ===  undefined )  { 
930915            // addition 
931-             index  =  ( this . #size ===  0  ? this . #tail
932-                 : this . #free. length  !==  0  ? this . #free. pop ( ) 
933-                     : this . #size ===  this . #max ? this . #evict( false ) 
916+             index  =  ( this . #size ===  0 
917+                 ? this . #tail
918+                 : this . #free. length  !==  0 
919+                     ? this . #free. pop ( ) 
920+                     : this . #size ===  this . #max
921+                         ? this . #evict( false ) 
934922                        : this . #size) ; 
935923            this . #keyList[ index ]  =  k ; 
936924            this . #valList[ index ]  =  v ; 
@@ -943,9 +931,6 @@ class LRUCache {
943931            if  ( status ) 
944932                status . set  =  'add' ; 
945933            noUpdateTTL  =  false ; 
946-             if  ( this . #hasOnInsert)  { 
947-                 this . #onInsert?. ( v ,  k ,  'add' ) ; 
948-             } 
949934        } 
950935        else  { 
951936            // update 
@@ -977,8 +962,8 @@ class LRUCache {
977962                this . #valList[ index ]  =  v ; 
978963                if  ( status )  { 
979964                    status . set  =  'replace' ; 
980-                     const  oldValue  =  oldVal  &&  this . #isBackgroundFetch( oldVal )  ? 
981-                         oldVal . __staleWhileFetching 
965+                     const  oldValue  =  oldVal  &&  this . #isBackgroundFetch( oldVal ) 
966+                         ?  oldVal . __staleWhileFetching 
982967                        : oldVal ; 
983968                    if  ( oldValue  !==  undefined ) 
984969                        status . oldValue  =  oldValue ; 
@@ -987,9 +972,6 @@ class LRUCache {
987972            else  if  ( status )  { 
988973                status . set  =  'update' ; 
989974            } 
990-             if  ( this . #hasOnInsert)  { 
991-                 this . onInsert ?. ( v ,  k ,  v  ===  oldVal  ? 'update'  : 'replace' ) ; 
992-             } 
993975        } 
994976        if  ( ttl  !==  0  &&  ! this . #ttls)  { 
995977            this . #initializeTTLTracking( ) ; 
@@ -1172,7 +1154,7 @@ class LRUCache {
11721154            const  bf  =  p ; 
11731155            if  ( this . #valList[ index ]  ===  p )  { 
11741156                if  ( v  ===  undefined )  { 
1175-                     if  ( bf . __staleWhileFetching   !==   undefined )  { 
1157+                     if  ( bf . __staleWhileFetching )  { 
11761158                        this . #valList[ index ]  =  bf . __staleWhileFetching ; 
11771159                    } 
11781160                    else  { 
0 commit comments