!function(e,t){"object"==typeofexports&&"undefined"!=typeofmodule?module.exports=t():"function"==typeofdefine&&define.amd?define(t):(e="undefined"!=typeofglobalThis?globalThis:e||self)["micro-memoize"]=t()}(this,(function(){"use strict";vare={isEqual:!0,isMatchingKey:!0,isPromise:!0,maxSize:!0,onCacheAdd:!0,onCacheChange:!0,onCacheHit:!0,transformKey:!0},t=Array.prototype.slice;functionn(e){varn=e.length;returnn?1===n?[e[0]]:2===n?[e[0],e[1]]:3===n?[e[0],e[1],e[2]]:t.call(e,0):[]}functioni(e,t){returne===t||e!=e&&t!=t}functiono(e,t){varn={};for(variine)n[i]=e[i];for(variint)n[i]=t[i];returnn}varr=function(){functione(e){this.keys=[],this.values=[],this.options=e;vart="function"==typeofe.isMatchingKey;t?this.getKeyIndex=this._getKeyIndexFromMatchingKey:e.maxSize>1?this.getKeyIndex=this._getKeyIndexForMany:this.getKeyIndex=this._getKeyIndexForSingle,this.canTransformKey="function"==typeofe.transformKey,this.shouldCloneArguments=this.canTransformKey||t,this.shouldUpdateOnAdd="function"==typeofe.onCacheAdd,this.shouldUpdateOnChange="function"==typeofe.onCacheChange,this.shouldUpdateOnHit="function"==typeofe.onCacheHit}returnObject.defineProperty(e.prototype,"size",{get:function(){returnthis.keys.length},enumerable:!1,configurable:!0}),Object.defineProperty(e.prototype,"snapshot",{get:function(){return{keys:n(this.keys),size:this.size,values:n(this.values)}},enumerable:!1,configurable:!0}),e.prototype._getKeyIndexFromMatchingKey=function(e){vart=this.options,n=t.isMatchingKey,i=t.maxSize,o=this.keys,r=o.length;if(!r)return-1;if(n(o[0],e))return0;if(i>1)for(vars=1;s<r;s++)if(n(o[s],e))returns;return-1},e.prototype._getKeyIndexForMany=function(e){vart=this.options.isEqual,n=this.keys,i=n.length;if(!i)return-1;if(1===i)returnthis._getKeyIndexForSingle(e);varo,r,s=e.length;if(s>1){for(vara=0;a<i;a++)if((o=n[a]).length===s){for(r=0;r<s&&t(o[r],e[r]);r++);if(r===s)returna}}elsefor(a=0;a<i;a++)if((o=n[a]).length===s&&t(o[0],e[0]))returna;return-1},e.prototype._getKeyIndexForSingle=function(e){vart=this.keys;if(!t.length)return-1;varn=t[0],i=n.length;if(e.length!==i)return-1;varo=this.options.isEqual;if(i>1){for(varr=0;r<i;r++)if(!o(n[r],e[r]))return-1;return0}returno(n[0],e[0])?0:-1},e.prototype.orderByLru=function(e,t,n){for(vari=this.keys,o=this.values,r=i.length,s=n;s--;)i[s+1]=i[s],o[s+1]=o[s];i[0]=e,o[0]=t;vara=this.options.maxSize;r===a&&n===r?(i.pop(),o.pop()):n>=a&&(i.length=o.length=a)},e.prototype.updateAsyncCache=function(e){vart=this,n=this.options,i=n.onCacheChange,o=n.onCacheHit,r=this.keys[0],s=this.values[0];this.values[0]=s.then((function(n){returnt.shouldUpdateOnHit&&o(t,t.options,e),t.shouldUpdateOnChange&&i(t,t.options,e),n}),(function(e){varn=t.getKeyIndex(r);throw-1!==n&&(t.keys.splice(n,1),t.values.splice(n,1)),e}))},e}();returnfunctiont(s,a){if(void0===a&&(a={}),function(e){return"function"==typeofe&&e.isMemoized}(s))returnt(s.fn,o(s.options,a));if("function"!=typeofs)thrownewTypeError("You must pass a function to `memoize`.");varh=a.isEqual,u=void0===h?i:h,f=a.isMatchingKey,c=a.isPromise,y=void0!==c&&c,d=a.maxSize,l=void0===d?1:d,p=a.onCacheAdd,g=a.onCacheChange,v=a.onCacheHit,m=a.transformKey,C=o({isEqual:u,isMatchingKey:f,isPromise:y,maxSize:l,onCacheAdd:p,onCacheChange:g,onCacheHit:v,transformKey:m},function(t){varn={};for(variint)e[i]||(n[i]=t[i]);returnn}(a)),K=newr(C),x=K.keys,z=K.values,I=K.canTransformKey,k=K.shouldCloneArguments,A=K.shouldUpdateOnAdd,M=K.shouldUpdateOnChange,O=K.shouldUpdateOnHit,b=function(){vare=k?n(arguments):arguments;I&&(e=m(e));vart=x.length?K.getKeyIndex(e):-1;if(-1!==t)O&&v(K,C,b),t&&(K.orderByLru(x[t],z[t],t),M&&g(K,C,b));else{vari=s.apply(this,arguments),o=k?e:n(arguments);K.orderByLru(o,i,x.length),y&&K.updateAsyncCache(b),A&&p(K,C,b),M&&g(K,C,b)}returnz[0]};returnb.cache=K,b.fn=s,b.isMemoized=!0,b.options=C,b}}));