You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

3 lines
11 KiB

2 years ago
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n(require("micro-memoize"),require("fast-equals")):"function"==typeof define&&define.amd?define(["micro-memoize","fast-equals"],n):(e="undefined"!=typeof globalThis?globalThis:e||self).moize=n(e.memoize,e.fe)}(this,(function(e,n){"use strict";function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}var r=t(e);function i(){return i=Object.assign||function(e){for(var n=1;n<arguments.length;n++){var t=arguments[n];for(var r in t)Object.prototype.hasOwnProperty.call(t,r)&&(e[r]=t[r])}return e},i.apply(this,arguments)}var o={isDeepEqual:!1,isPromise:!1,isReact:!1,isSerialized:!1,isShallowEqual:!1,matchesArg:void 0,matchesKey:void 0,maxAge:void 0,maxArgs:void 0,maxSize:1,onExpire:void 0,profileName:void 0,serializer:void 0,updateCacheForKey:void 0,transformArgs:void 0,updateExpire:!1};function a(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];return n.reduce((function(e,n){return"function"==typeof e?"function"==typeof n?function(){e.apply(this,arguments),n.apply(this,arguments)}:e:"function"==typeof n?n:void 0}))}function u(){for(var e=arguments.length,n=new Array(e),t=0;t<e;t++)n[t]=arguments[t];return n.reduce((function(e,n){return"function"==typeof e?"function"==typeof n?function(){return e(n.apply(this,arguments))}:e:"function"==typeof n?n:void 0}))}function s(e,n){for(var t=0;t<e.length;t++)if(e[t].key===n)return t;return-1}function c(e,n){var t="function"==typeof n?n:function(n,t){for(var r=0;r<t.length;r++)if(!e(n[r],t[r]))return!1;return!0};return function(e,n){for(var r=0;r<e.length;r++)if(e[r].length===n.length&&t(e[r],n))return r;return-1}}function f(e,n){return n&&n!==o?i({},e,n,{onCacheAdd:a(e.onCacheAdd,n.onCacheAdd),onCacheChange:a(e.onCacheChange,n.onCacheChange),onCacheHit:a(e.onCacheHit,n.onCacheHit),transformArgs:u(e.transformArgs,n.transformArgs)}):e}function l(e,n,t){try{var r=t||n||"anonymous";Object.defineProperty(e,"name",{configurable:!0,enumerable:!1,value:"moized("+r+")",writable:!0})}catch(e){}}function p(e,n,t){var r=s(e,n);-1!==r&&(clearTimeout(e[r].timeoutId),t&&e.splice(r,1))}function m(e,n){var t=setTimeout(e,n);return"function"==typeof t.unref&&t.unref(),t}function h(e,n){return function(t){var r=t.keys[0],i=s(e,r);~i&&(p(e,r,!1),e[i].timeoutId=m(e[i].expirationMethod,n.maxAge))}}function g(e,n,t,r){var i="number"==typeof n.maxAge&&isFinite(n.maxAge)?function(e,n,t,r){var i=n.maxAge;return function o(a,u,f){var l=a.keys[0];if(-1===s(e,l)){var h=function(){var i=c(t,r)(a.keys,l),s=a.values[i];~i&&(a.keys.splice(i,1),a.values.splice(i,1),"function"==typeof n.onCacheChange&&n.onCacheChange(a,u,f)),p(e,l,!0),"function"==typeof n.onExpire&&!1===n.onExpire(l)&&(a.keys.unshift(l),a.values.unshift(s),o(a,u,f),"function"==typeof n.onCacheChange&&n.onCacheChange(a,u,f))};e.push({expirationMethod:h,key:l,timeoutId:m(h,i)})}}}(e,n,t,r):void 0;return{onCacheAdd:i,onCacheHit:i&&n.updateExpire?h(e,n):void 0}}var y={anonymousProfileNameCounter:1,isCollectingStats:!1,profiles:{}},d=!1;function v(e){e?delete y.profiles[e]:y.profiles={}}function x(e){var n=e.profileName;return function(){n&&!y.profiles[n]&&(y.profiles[n]={calls:0,hits:0}),y.profiles[n].calls++}}function C(e){return function(){var n=y.profiles,t=e.profileName;n[t]||(n[t]={calls:0,hits:0}),n[t].calls++,n[t].hits++}}function A(e){var n=(new Error).stack,t=e.displayName||e.name||"Anonymous "+y.anonymousProfileNameCounter++;if(!n)return t;for(var r,i,o=n.split("\n").slice(3),a=0;a<o.length;a++)if(-1===(r=o[a]).indexOf("/moize/")&&-1===r.indexOf(" (native)")&&-1===r.indexOf(" Function.")){i=r.replace(/\n/g,"\\n").trim();break}return i?t+" "+i:t}function z(e,n){return e?(n/e*100).toFixed(4)+"%":"0.0000%"}function S(e){y.isCollectingStats||d||(console.warn('Stats are not currently being collected, please run "collectStats" to enable them.'),d=!0);var n=y.profiles;if(e){if(!n[e])return{calls:0,hits:0,usage:"0.0000%"};var t=n[e];return i({},t,{usage:z(t.calls,t.hits)})}var r=Object.keys(y.profiles).reduce((function(e,t){return e.cal
//# sourceMappingURL=moize.min.js.map