hexo/node_modules/moize/dist/moize.min.js

3 lines
11 KiB
JavaScript

!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(){return t=Object.assign?Object.assign.bind():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},t.apply(this,arguments)}var r={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 i(){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 o(){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 a(e,n){for(var t=0;t<e.length;t++)if(e[t].key===n)return t;return-1}function u(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 s(e,n){return n&&n!==r?t({},e,n,{onCacheAdd:i(e.onCacheAdd,n.onCacheAdd),onCacheChange:i(e.onCacheChange,n.onCacheChange),onCacheHit:i(e.onCacheHit,n.onCacheHit),transformArgs:o(e.transformArgs,n.transformArgs)}):e}function c(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 f(e,n,t){var r=a(e,n);-1!==r&&(clearTimeout(e[r].timeoutId),t&&e.splice(r,1))}function l(e,n){var t=setTimeout(e,n);return"function"==typeof t.unref&&t.unref(),t}function p(e,n){return function(t){var r=t.keys[0],i=a(e,r);~i&&(f(e,r,!1),e[i].timeoutId=l(e[i].expirationMethod,n.maxAge))}}function m(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(s,c,p){var m=s.keys[0];if(-1===a(e,m)){var h=function(){var i=u(t,r)(s.keys,m),a=s.values[i];~i&&(s.keys.splice(i,1),s.values.splice(i,1),"function"==typeof n.onCacheChange&&n.onCacheChange(s,c,p)),f(e,m,!0),"function"==typeof n.onExpire&&!1===n.onExpire(m)&&(s.keys.unshift(m),s.values.unshift(a),o(s,c,p),"function"==typeof n.onCacheChange&&n.onCacheChange(s,c,p))};e.push({expirationMethod:h,key:m,timeoutId:l(h,i)})}}}(e,n,t,r):void 0;return{onCacheAdd:i,onCacheHit:i&&n.updateExpire?p(e,n):void 0}}var h={anonymousProfileNameCounter:1,isCollectingStats:!1,profiles:{}},g=!1;function y(e){e?delete h.profiles[e]:h.profiles={}}function d(e){var n=e.profileName;return function(){n&&!h.profiles[n]&&(h.profiles[n]={calls:0,hits:0}),h.profiles[n].calls++}}function v(e){return function(){var n=h.profiles,t=e.profileName;n[t]||(n[t]={calls:0,hits:0}),n[t].calls++,n[t].hits++}}function x(e){return e.displayName||e.name||"Anonymous "+h.anonymousProfileNameCounter++}function C(e,n){return e?(n/e*100).toFixed(4)+"%":"0.0000%"}function A(e){h.isCollectingStats||g||(console.warn('Stats are not currently being collected, please run "collectStats" to enable them.'),g=!0);var n=h.profiles;if(e){if(!n[e])return{calls:0,hits:0,usage:"0.0000%"};var r=n[e];return t({},r,{usage:C(r.calls,r.hits)})}var i=Object.keys(h.profiles).reduce((function(e,t){return e.calls+=n[t].calls,e.hits+=n[t].hits,e}),{calls:0,hits:0});return t({},i,{profiles:Object.keys(n).reduce((function(e,n){return e[n]=A(n),e}),{}),usage:C(i.calls,i.hits)})}var z={arguments:!0,callee:!0,caller:!0,constructor:!0,length:!0,name:!0,prototype:!0};function S(e,n,t){void 0===t&&(t=[]),Object.getOwnPropertyNames(e).forEach((function(r){if(!z[r]&&-1===t.indexOf(r)){var i=Object.getOwnPropertyDescriptor(e,r);i.get||i.set?Object.defineProperty(n,r,i):n[r]=e[r]}}))}function b(e,n){return function(e,n){var t=n.expirations,r=e.options,i=u(r.isEqual,r.isMatchingKey),o=e;o.clear=function(){var e=o._microMemoizeOptions.onCacheChange,n=o.cache;return n.keys.length=0,n.values.length=0,e&&e(n,o.options,o),!0},o.clearStats=function(){y(o.options.profileName)},o.get=function(e){var n=o._microMemoizeOptions.transformKey,t=o.cache,r=n?n(e):e;return-1!==i(t.keys,r)?o.apply(this,e):void 0},o.getStats=function(){return A(o.options.profileName)},o.has=function(e){var n=o._microMemoizeOptions.transformKey,t=n?n(e):e;return-1!==i(o.cache.keys,t)},o.keys=function(){return o.cacheSnapshot.keys},o.remove=function(e){var n=o._microMemoizeOptions,r=n.onCacheChange,a=n.transformKey,u=o.cache,s=i(u.keys,a?a(e):e);if(-1===s)return!1;var c=u.keys[s];return u.keys.splice(s,1),u.values.splice(s,1),r&&r(u,o.options,o),f(t,c,!0),!0},o.set=function(e,n){var t=o._microMemoizeOptions,r=o.cache,a=o.options,u=t.onCacheAdd,s=t.onCacheChange,c=t.transformKey,f=c?c(e):e,l=i(r.keys,f);if(-1===l){var p=a.maxSize-1;r.size>p&&(r.keys.length=p,r.values.length=p),r.keys.unshift(f),r.values.unshift(n),a.isPromise&&r.updateAsyncCache(o),u&&u(r,a,o),s&&s(r,a,o)}else{var m=r.keys[l];r.values[l]=n,l>0&&r.orderByLru(m,n,l),a.isPromise&&r.updateAsyncCache(o),"function"==typeof s&&s(r,a,o)}},o.values=function(){return o.cacheSnapshot.values}}(e,n),function(e,n){var t=n.expirations,r=n.options,i=n.originalFunction,o=e.options;Object.defineProperties(e,{_microMemoizeOptions:{configurable:!0,get:function(){return o}},cacheSnapshot:{configurable:!0,get:function(){var n=e.cache;return{keys:n.keys.slice(0),size:n.size,values:n.values.slice(0)}}},expirations:{configurable:!0,get:function(){return t}},expirationsSnapshot:{configurable:!0,get:function(){return t.slice(0)}},isMoized:{configurable:!0,get:function(){return!0}},options:{configurable:!0,get:function(){return r}},originalFunction:{configurable:!0,get:function(){return i}}}),S(i,e)}(e,n),e}var E="function"==typeof Symbol&&Symbol.for?Symbol.for("react.element"):60103;function k(e,n){for(var t=e.length,r=0;r<t;++r)if(e[r]===n)return r+1;return 0}function O(e){var n,t,r=typeof e;return!e||"object"!==r&&"function"!==r?e:JSON.stringify(e,(n=[],t=[],function(e,r){var i=typeof r;if("function"===i||"symbol"===i)return r.toString();if("object"==typeof r){if(n.length){var o=k(n,this);0===o?n[n.length]=this:(n.splice(o),t.splice(o)),t[t.length]=e;var a=k(n,r);if(0!==a)return"[ref="+(t.slice(0,a).join(".")||".")+"]"}else n[0]=r,t[0]=e;return r}return""+r}))}function N(e){for(var n="|",t=0;t<e.length;t++)n+=O(e[t])+"|";return[n]}function q(e,n){return e[0]===n[0]}function K(e){if("function"==typeof e)return function(n,t,r){return e(r.cache,r.options,r)}}function j(e){return o(e.isSerialized&&function(e){return"function"==typeof e.serializer?e.serializer:N}(e),"function"==typeof e.transformArgs&&e.transformArgs,"number"==typeof e.maxArgs&&(n=e.maxArgs,function(e){if(n>=e.length)return e;if(0===n)return[];if(1===n)return[e[0]];if(2===n)return[e[0],e[1]];if(3===n)return[e[0],e[1],e[2]];for(var t=[],r=0;r<n;r++)t[r]=e[r];return t}));var n}var w=["matchesArg","isDeepEqual","isPromise","isReact","isSerialized","isShallowEqual","matchesKey","maxAge","maxArgs","maxSize","onCacheAdd","onCacheChange","onCacheHit","onExpire","profileName","serializer","updateCacheForKey","transformArgs","updateExpire"],M=function o(a,u){var f=u||r;if(function(e){return"function"==typeof e&&e.isMoized}(a)){var l=a.originalFunction,p=s(a.options,f);return o(l,p)}if("object"==typeof a)return function(e,n){if("function"==typeof e){var t=s(a,n);return o(e,t)}var r=s(a,e);return o(r)};if(f.isReact)return function(e,n,r){var i=e(t({maxArgs:2,isShallowEqual:!0},r,{isReact:!1}));function o(e,t,r){this.props=e,this.context=t,this.updater=r,this.MoizedComponent=i(n)}return n.displayName||(n.displayName=n.name||"Component"),o.prototype.isReactComponent={},o.prototype.render=function(){return{$$typeof:E,type:this.MoizedComponent,props:this.props,ref:null,key:null,_owner:null}},S(n,o,["contextType","contextTypes"]),o.displayName="Moized("+(n.displayName||n.name||"Component")+")",c(o,n.name,r.profileName),o}(o,a,f);var g=t({},r,f,{maxAge:"number"==typeof f.maxAge&&f.maxAge>=0?f.maxAge:r.maxAge,maxArgs:"number"==typeof f.maxArgs&&f.maxArgs>=0?f.maxArgs:r.maxArgs,maxSize:"number"==typeof f.maxSize&&f.maxSize>=0?f.maxSize:r.maxSize,profileName:f.profileName||x(a)}),y=[];g.matchesArg,g.isDeepEqual;var C=g.isPromise;g.isReact,g.isSerialized,g.isShallowEqual,g.matchesKey,g.maxAge,g.maxArgs;var A=g.maxSize,z=g.onCacheAdd,k=g.onCacheChange,O=g.onCacheHit;g.onExpire,g.profileName,g.serializer;var N=g.updateCacheForKey;g.transformArgs,g.updateExpire;var M=function(e,n){if(null==e)return{};var t,r,i={},o=Object.keys(e);for(r=0;r<o.length;r++)t=o[r],n.indexOf(t)>=0||(i[t]=e[t]);return i}(g,w),P=function(e){return e.matchesArg||e.isDeepEqual&&n.deepEqual||e.isShallowEqual&&n.shallowEqual||n.sameValueZeroEqual}(g),F=function(e){return e.matchesKey||e.isSerialized&&q||void 0}(g),H=m(y,g,P,F),R=function(e){return h.isCollectingStats?{onCacheAdd:d(e),onCacheHit:v(e)}:{}}(g),_=j(g),D=t({},M,{isEqual:P,isMatchingKey:F,isPromise:C,maxSize:A,onCacheAdd:K(i(z,H.onCacheAdd,R.onCacheAdd)),onCacheChange:K(k),onCacheHit:K(i(O,H.onCacheHit,R.onCacheHit)),transformKey:_}),T=b(e(a,D),{expirations:y,options:g,originalFunction:a});return N&&(T=function(e){var n=e.options.updateCacheForKey,t=function(){for(var t=arguments.length,r=new Array(t),i=0;i<t;i++)r[i]=arguments[i];if(!n(r))return e.apply(this,r);var o=e.fn.apply(this,r);return e.set(r,o),o};return S(e,t),t}(T)),c(T,a.name,f.profileName),T};return M.clearStats=y,M.collectStats=function(e){void 0===e&&(e=!0),h.isCollectingStats=e},M.compose=function(){return o.apply(void 0,arguments)||M},M.deep=M({isDeepEqual:!0}),M.getStats=A,M.infinite=M({maxSize:1/0}),M.isCollectingStats=function(){return h.isCollectingStats},M.isMoized=function(e){return"function"==typeof e&&!!e.isMoized},M.matchesArg=function(e){return M({matchesArg:e})},M.matchesKey=function(e){return M({matchesKey:e})},M.maxAge=function(e,n){if(!0===n)return M({maxAge:e,updateExpire:n});if("object"==typeof n){var t=n.onExpire,r=n.updateExpire;return M({maxAge:e,onExpire:t,updateExpire:r})}return M("function"==typeof n?{maxAge:e,onExpire:n,updateExpire:!0}:{maxAge:e})},M.maxArgs=function(e){return M({maxArgs:e})},M.maxSize=function(e){return M({maxSize:e})},M.profile=function(e){return M({profileName:e})},M.promise=M({isPromise:!0,updateExpire:!0}),M.react=M({isReact:!0}),M.serialize=M({isSerialized:!0}),M.serializeWith=function(e){return M({isSerialized:!0,serializer:e})},M.shallow=M({isShallowEqual:!0}),M.transformArgs=function(e){return M({transformArgs:e})},M.updateCacheForKey=function(e){return M({updateCacheForKey:e})},Object.defineProperty(M,"default",{configurable:!1,enumerable:!1,value:M,writable:!1}),M}));
//# sourceMappingURL=moize.min.js.map