Comparing version 6.1.1 to 6.1.2
# moize CHANGELOG | ||
## 6.1.2 | ||
- [#176](https://github.com/planttheidea/moize/issues/176) - Remove use of `new Error().stack` in derivation of fallback `profileName`, due to potential for OOM crashes in specific scenarios | ||
## 6.1.1 | ||
@@ -4,0 +8,0 @@ |
@@ -11,3 +11,3 @@ 'use strict'; | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
_extends = Object.assign ? Object.assign.bind() : function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
@@ -25,3 +25,2 @@ var source = arguments[i]; | ||
}; | ||
return _extends.apply(this, arguments); | ||
@@ -432,23 +431,3 @@ } | ||
function getDefaultProfileName(fn) { | ||
var stack = new Error().stack; | ||
var fnName = fn.displayName || fn.name || "Anonymous " + statsCache.anonymousProfileNameCounter++; | ||
if (!stack) { | ||
return fnName; | ||
} | ||
var lines = stack.split('\n').slice(3); | ||
var line; | ||
var profileNameLocation; | ||
for (var index = 0; index < lines.length; index++) { | ||
line = lines[index]; | ||
if (line.indexOf('/moize/') === -1 && line.indexOf(' (native)') === -1 && line.indexOf(' Function.') === -1) { | ||
profileNameLocation = line.replace(/\n/g, '\\n').trim(); | ||
break; | ||
} | ||
} | ||
return profileNameLocation ? fnName + " " + profileNameLocation : fnName; | ||
return fn.displayName || fn.name || "Anonymous " + statsCache.anonymousProfileNameCounter++; | ||
} | ||
@@ -455,0 +434,0 @@ /** |
@@ -5,3 +5,3 @@ import memoize from 'micro-memoize'; | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
_extends = Object.assign ? Object.assign.bind() : function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
@@ -19,3 +19,2 @@ var source = arguments[i]; | ||
}; | ||
return _extends.apply(this, arguments); | ||
@@ -426,23 +425,3 @@ } | ||
function getDefaultProfileName(fn) { | ||
var stack = new Error().stack; | ||
var fnName = fn.displayName || fn.name || "Anonymous " + statsCache.anonymousProfileNameCounter++; | ||
if (!stack) { | ||
return fnName; | ||
} | ||
var lines = stack.split('\n').slice(3); | ||
var line; | ||
var profileNameLocation; | ||
for (var index = 0; index < lines.length; index++) { | ||
line = lines[index]; | ||
if (line.indexOf('/moize/') === -1 && line.indexOf(' (native)') === -1 && line.indexOf(' Function.') === -1) { | ||
profileNameLocation = line.replace(/\n/g, '\\n').trim(); | ||
break; | ||
} | ||
} | ||
return profileNameLocation ? fnName + " " + profileNameLocation : fnName; | ||
return fn.displayName || fn.name || "Anonymous " + statsCache.anonymousProfileNameCounter++; | ||
} | ||
@@ -449,0 +428,0 @@ /** |
@@ -12,3 +12,3 @@ (function (global, factory) { | ||
function _extends() { | ||
_extends = Object.assign || function (target) { | ||
_extends = Object.assign ? Object.assign.bind() : function (target) { | ||
for (var i = 1; i < arguments.length; i++) { | ||
@@ -26,3 +26,2 @@ var source = arguments[i]; | ||
}; | ||
return _extends.apply(this, arguments); | ||
@@ -433,23 +432,3 @@ } | ||
function getDefaultProfileName(fn) { | ||
var stack = new Error().stack; | ||
var fnName = fn.displayName || fn.name || "Anonymous " + statsCache.anonymousProfileNameCounter++; | ||
if (!stack) { | ||
return fnName; | ||
} | ||
var lines = stack.split('\n').slice(3); | ||
var line; | ||
var profileNameLocation; | ||
for (var index = 0; index < lines.length; index++) { | ||
line = lines[index]; | ||
if (line.indexOf('/moize/') === -1 && line.indexOf(' (native)') === -1 && line.indexOf(' Function.') === -1) { | ||
profileNameLocation = line.replace(/\n/g, '\\n').trim(); | ||
break; | ||
} | ||
} | ||
return profileNameLocation ? fnName + " " + profileNameLocation : fnName; | ||
return fn.displayName || fn.name || "Anonymous " + statsCache.anonymousProfileNameCounter++; | ||
} | ||
@@ -456,0 +435,0 @@ /** |
@@ -1,2 +0,2 @@ | ||
!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.calls+=n[t].calls,e.hits+=n[t].hits,e}),{calls:0,hits:0});return i({},r,{profiles:Object.keys(n).reduce((function(e,n){return e[n]=S(n),e}),{}),usage:z(r.calls,r.hits)})}var b={arguments:!0,callee:!0,caller:!0,constructor:!0,length:!0,name:!0,prototype:!0};function E(e,n,t){void 0===t&&(t=[]),Object.getOwnPropertyNames(e).forEach((function(r){if(!b[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 k(e,n){return function(e,n){var t=n.expirations,r=e.options,i=c(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(){v(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 S(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),p(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}}}),E(i,e)}(e,n),e}var O="function"==typeof Symbol&&Symbol.for?Symbol.for("react.element"):60103;function N(e,n){for(var t=e.length,r=0;r<t;++r)if(e[r]===n)return r+1;return 0}function q(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=N(n,this);0===o?n[n.length]=this:(n.splice(o),t.splice(o)),t[t.length]=e;var a=N(n,r);if(0!==a)return"[ref="+(t.slice(0,a).join(".")||".")+"]"}else n[0]=r,t[0]=e;return r}return""+r}))}function w(e){for(var n="|",t=0;t<e.length;t++)n+=q(e[t])+"|";return[n]}function K(e,n){return e[0]===n[0]}function j(e){if("function"==typeof e)return function(n,t,r){return e(r.cache,r.options,r)}}function M(e){return u(e.isSerialized&&function(e){return"function"==typeof e.serializer?e.serializer:w}(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 P=["matchesArg","isDeepEqual","isPromise","isReact","isSerialized","isShallowEqual","matchesKey","maxAge","maxArgs","maxSize","onCacheAdd","onCacheChange","onCacheHit","onExpire","profileName","serializer","updateCacheForKey","transformArgs","updateExpire"],F=function e(t,u){var s=u||o;if(function(e){return"function"==typeof e&&e.isMoized}(t)){var c=t.originalFunction,p=f(t.options,s);return e(c,p)}if("object"==typeof t)return function(n,r){if("function"==typeof n){var i=f(t,r);return e(n,i)}var o=f(t,n);return e(o)};if(s.isReact)return function(e,n,t){var r=e(i({maxArgs:2,isShallowEqual:!0},t,{isReact:!1}));function o(e,t,i){this.props=e,this.context=t,this.updater=i,this.MoizedComponent=r(n)}return n.displayName||(n.displayName=n.name||"Component"),o.prototype.isReactComponent={},o.prototype.render=function(){return{$$typeof:O,type:this.MoizedComponent,props:this.props,ref:null,key:null,_owner:null}},E(n,o,["contextType","contextTypes"]),o.displayName="Moized("+(n.displayName||n.name||"Component")+")",l(o,n.name,t.profileName),o}(e,t,s);var m=i({},o,s,{maxAge:"number"==typeof s.maxAge&&s.maxAge>=0?s.maxAge:o.maxAge,maxArgs:"number"==typeof s.maxArgs&&s.maxArgs>=0?s.maxArgs:o.maxArgs,maxSize:"number"==typeof s.maxSize&&s.maxSize>=0?s.maxSize:o.maxSize,profileName:s.profileName||A(t)}),h=[];m.matchesArg,m.isDeepEqual;var d=m.isPromise;m.isReact,m.isSerialized,m.isShallowEqual,m.matchesKey,m.maxAge,m.maxArgs;var v=m.maxSize,z=m.onCacheAdd,S=m.onCacheChange,b=m.onCacheHit;m.onExpire,m.profileName,m.serializer;var N=m.updateCacheForKey;m.transformArgs,m.updateExpire;var q=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}(m,P),w=function(e){return e.matchesArg||e.isDeepEqual&&n.deepEqual||e.isShallowEqual&&n.shallowEqual||n.sameValueZeroEqual}(m),F=function(e){return e.matchesKey||e.isSerialized&&K||void 0}(m),H=g(h,m,w,F),R=function(e){return y.isCollectingStats?{onCacheAdd:x(e),onCacheHit:C(e)}:{}}(m),_=M(m),D=i({},q,{isEqual:w,isMatchingKey:F,isPromise:d,maxSize:v,onCacheAdd:j(a(z,H.onCacheAdd,R.onCacheAdd)),onCacheChange:j(S),onCacheHit:j(a(b,H.onCacheHit,R.onCacheHit)),transformKey:_}),T=k(r.default(t,D),{expirations:h,options:m,originalFunction:t});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 E(e,t),t}(T)),l(T,t.name,s.profileName),T};return F.clearStats=v,F.collectStats=function(e){void 0===e&&(e=!0),y.isCollectingStats=e},F.compose=function(){return u.apply(void 0,arguments)||F},F.deep=F({isDeepEqual:!0}),F.getStats=S,F.infinite=F({maxSize:1/0}),F.isCollectingStats=function(){return y.isCollectingStats},F.isMoized=function(e){return"function"==typeof e&&!!e.isMoized},F.matchesArg=function(e){return F({matchesArg:e})},F.matchesKey=function(e){return F({matchesKey:e})},F.maxAge=function(e,n){if(!0===n)return F({maxAge:e,updateExpire:n});if("object"==typeof n){var t=n.onExpire,r=n.updateExpire;return F({maxAge:e,onExpire:t,updateExpire:r})}return F("function"==typeof n?{maxAge:e,onExpire:n,updateExpire:!0}:{maxAge:e})},F.maxArgs=function(e){return F({maxArgs:e})},F.maxSize=function(e){return F({maxSize:e})},F.profile=function(e){return F({profileName:e})},F.promise=F({isPromise:!0,updateExpire:!0}),F.react=F({isReact:!0}),F.serialize=F({isSerialized:!0}),F.serializeWith=function(e){return F({isSerialized:!0,serializer:e})},F.shallow=F({isShallowEqual:!0}),F.transformArgs=function(e){return F({transformArgs:e})},F.updateCacheForKey=function(e){return F({updateCacheForKey:e})},Object.defineProperty(F,"default",{configurable:!1,enumerable:!1,value:F,writable:!1}),F})); | ||
!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?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},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){return e.displayName||e.name||"Anonymous "+y.anonymousProfileNameCounter++}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.calls+=n[t].calls,e.hits+=n[t].hits,e}),{calls:0,hits:0});return i({},r,{profiles:Object.keys(n).reduce((function(e,n){return e[n]=S(n),e}),{}),usage:z(r.calls,r.hits)})}var b={arguments:!0,callee:!0,caller:!0,constructor:!0,length:!0,name:!0,prototype:!0};function E(e,n,t){void 0===t&&(t=[]),Object.getOwnPropertyNames(e).forEach((function(r){if(!b[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 k(e,n){return function(e,n){var t=n.expirations,r=e.options,i=c(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(){v(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 S(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),p(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}}}),E(i,e)}(e,n),e}var O="function"==typeof Symbol&&Symbol.for?Symbol.for("react.element"):60103;function N(e,n){for(var t=e.length,r=0;r<t;++r)if(e[r]===n)return r+1;return 0}function q(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=N(n,this);0===o?n[n.length]=this:(n.splice(o),t.splice(o)),t[t.length]=e;var a=N(n,r);if(0!==a)return"[ref="+(t.slice(0,a).join(".")||".")+"]"}else n[0]=r,t[0]=e;return r}return""+r}))}function j(e){for(var n="|",t=0;t<e.length;t++)n+=q(e[t])+"|";return[n]}function K(e,n){return e[0]===n[0]}function w(e){if("function"==typeof e)return function(n,t,r){return e(r.cache,r.options,r)}}function M(e){return u(e.isSerialized&&function(e){return"function"==typeof e.serializer?e.serializer:j}(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 P=["matchesArg","isDeepEqual","isPromise","isReact","isSerialized","isShallowEqual","matchesKey","maxAge","maxArgs","maxSize","onCacheAdd","onCacheChange","onCacheHit","onExpire","profileName","serializer","updateCacheForKey","transformArgs","updateExpire"],F=function e(t,u){var s=u||o;if(function(e){return"function"==typeof e&&e.isMoized}(t)){var c=t.originalFunction,p=f(t.options,s);return e(c,p)}if("object"==typeof t)return function(n,r){if("function"==typeof n){var i=f(t,r);return e(n,i)}var o=f(t,n);return e(o)};if(s.isReact)return function(e,n,t){var r=e(i({maxArgs:2,isShallowEqual:!0},t,{isReact:!1}));function o(e,t,i){this.props=e,this.context=t,this.updater=i,this.MoizedComponent=r(n)}return n.displayName||(n.displayName=n.name||"Component"),o.prototype.isReactComponent={},o.prototype.render=function(){return{$$typeof:O,type:this.MoizedComponent,props:this.props,ref:null,key:null,_owner:null}},E(n,o,["contextType","contextTypes"]),o.displayName="Moized("+(n.displayName||n.name||"Component")+")",l(o,n.name,t.profileName),o}(e,t,s);var m=i({},o,s,{maxAge:"number"==typeof s.maxAge&&s.maxAge>=0?s.maxAge:o.maxAge,maxArgs:"number"==typeof s.maxArgs&&s.maxArgs>=0?s.maxArgs:o.maxArgs,maxSize:"number"==typeof s.maxSize&&s.maxSize>=0?s.maxSize:o.maxSize,profileName:s.profileName||A(t)}),h=[];m.matchesArg,m.isDeepEqual;var d=m.isPromise;m.isReact,m.isSerialized,m.isShallowEqual,m.matchesKey,m.maxAge,m.maxArgs;var v=m.maxSize,z=m.onCacheAdd,S=m.onCacheChange,b=m.onCacheHit;m.onExpire,m.profileName,m.serializer;var N=m.updateCacheForKey;m.transformArgs,m.updateExpire;var q=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}(m,P),j=function(e){return e.matchesArg||e.isDeepEqual&&n.deepEqual||e.isShallowEqual&&n.shallowEqual||n.sameValueZeroEqual}(m),F=function(e){return e.matchesKey||e.isSerialized&&K||void 0}(m),H=g(h,m,j,F),R=function(e){return y.isCollectingStats?{onCacheAdd:x(e),onCacheHit:C(e)}:{}}(m),_=M(m),D=i({},q,{isEqual:j,isMatchingKey:F,isPromise:d,maxSize:v,onCacheAdd:w(a(z,H.onCacheAdd,R.onCacheAdd)),onCacheChange:w(S),onCacheHit:w(a(b,H.onCacheHit,R.onCacheHit)),transformKey:_}),T=k(r.default(t,D),{expirations:h,options:m,originalFunction:t});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 E(e,t),t}(T)),l(T,t.name,s.profileName),T};return F.clearStats=v,F.collectStats=function(e){void 0===e&&(e=!0),y.isCollectingStats=e},F.compose=function(){return u.apply(void 0,arguments)||F},F.deep=F({isDeepEqual:!0}),F.getStats=S,F.infinite=F({maxSize:1/0}),F.isCollectingStats=function(){return y.isCollectingStats},F.isMoized=function(e){return"function"==typeof e&&!!e.isMoized},F.matchesArg=function(e){return F({matchesArg:e})},F.matchesKey=function(e){return F({matchesKey:e})},F.maxAge=function(e,n){if(!0===n)return F({maxAge:e,updateExpire:n});if("object"==typeof n){var t=n.onExpire,r=n.updateExpire;return F({maxAge:e,onExpire:t,updateExpire:r})}return F("function"==typeof n?{maxAge:e,onExpire:n,updateExpire:!0}:{maxAge:e})},F.maxArgs=function(e){return F({maxArgs:e})},F.maxSize=function(e){return F({maxSize:e})},F.profile=function(e){return F({profileName:e})},F.promise=F({isPromise:!0,updateExpire:!0}),F.react=F({isReact:!0}),F.serialize=F({isSerialized:!0}),F.serializeWith=function(e){return F({isSerialized:!0,serializer:e})},F.shallow=F({isShallowEqual:!0}),F.transformArgs=function(e){return F({transformArgs:e})},F.updateCacheForKey=function(e){return F({updateCacheForKey:e})},Object.defineProperty(F,"default",{configurable:!1,enumerable:!1,value:F,writable:!1}),F})); | ||
//# sourceMappingURL=moize.min.js.map |
@@ -17,25 +17,25 @@ { | ||
"fast-equals": "^3.0.1", | ||
"micro-memoize": "^4.0.9" | ||
"micro-memoize": "^4.0.11" | ||
}, | ||
"description": "Blazing fast memoization based on all parameters passed", | ||
"devDependencies": { | ||
"@babel/cli": "7.17.6", | ||
"@babel/core": "7.17.9", | ||
"@babel/plugin-proposal-class-properties": "7.16.7", | ||
"@babel/preset-env": "7.16.11", | ||
"@babel/preset-react": "7.16.7", | ||
"@babel/preset-typescript": "7.16.7", | ||
"@babel/cli": "7.18.10", | ||
"@babel/core": "7.18.10", | ||
"@babel/plugin-proposal-class-properties": "7.18.6", | ||
"@babel/preset-env": "7.18.10", | ||
"@babel/preset-react": "7.18.6", | ||
"@babel/preset-typescript": "7.18.6", | ||
"@rollup/plugin-babel": "5.3.1", | ||
"@rollup/plugin-commonjs": "21.1.0", | ||
"@rollup/plugin-node-resolve": "13.2.1", | ||
"@rollup/plugin-commonjs": "22.0.2", | ||
"@rollup/plugin-node-resolve": "13.3.0", | ||
"@types/bluebird": "3.5.36", | ||
"@types/eslint": "^8.4.1", | ||
"@types/jest": "27.4.1", | ||
"@types/lodash": "4.14.182", | ||
"@types/memoizee": "0.4.7", | ||
"@types/react": "18.0.6", | ||
"@types/react-dom": "18.0.2", | ||
"@typescript-eslint/eslint-plugin": "5.20.0", | ||
"@typescript-eslint/parser": "5.20.0", | ||
"babel-jest": "27.5.1", | ||
"@types/eslint": "^8.4.6", | ||
"@types/jest": "28.1.7", | ||
"@types/lodash": "4.14.184", | ||
"@types/memoizee": "0.4.8", | ||
"@types/react": "18.0.17", | ||
"@types/react-dom": "18.0.6", | ||
"@typescript-eslint/eslint-plugin": "5.33.1", | ||
"@typescript-eslint/parser": "5.33.1", | ||
"babel-jest": "28.1.3", | ||
"babel-loader": "8.2.5", | ||
@@ -45,7 +45,7 @@ "benchmark": "2.1.4", | ||
"cli-table2": "0.2.0", | ||
"core-js": "3.22.2", | ||
"eslint": "8.14.0", | ||
"core-js": "3.24.1", | ||
"eslint": "8.22.0", | ||
"eslint-friendly-formatter": "4.0.1", | ||
"eslint-plugin-react": "7.29.4", | ||
"eslint-webpack-plugin": "^3.1.1", | ||
"eslint-plugin-react": "7.30.1", | ||
"eslint-webpack-plugin": "^3.2.0", | ||
"fast-memoize": "2.5.2", | ||
@@ -55,4 +55,5 @@ "html-webpack-plugin": "5.5.0", | ||
"ink-docstrap": "1.3.2", | ||
"jest": "27.5.1", | ||
"jsdoc": "3.6.10", | ||
"jest": "28.1.3", | ||
"jest-environment-jsdom": "^28.1.3", | ||
"jsdoc": "3.6.11", | ||
"jsdoc-babel": "0.5.0", | ||
@@ -64,20 +65,20 @@ "lodash": "4.17.21", | ||
"memoizerific": "1.11.3", | ||
"ora": "6.1.0", | ||
"ora": "6.1.2", | ||
"prop-types": "15.8.1", | ||
"q": "1.5.1", | ||
"ramda": "0.28.0", | ||
"react": "18.0.0", | ||
"react-dom": "18.0.0", | ||
"react": "18.2.0", | ||
"react-dom": "18.2.0", | ||
"regenerator-runtime": "0.13.9", | ||
"release-it": "^14.14.2", | ||
"release-it": "^15.3.0", | ||
"rimraf": "3.0.2", | ||
"rollup": "2.70.2", | ||
"rollup": "2.78.1", | ||
"rollup-plugin-terser": "7.0.2", | ||
"tslib": "2.4.0", | ||
"typedoc": "0.22.15", | ||
"typescript": "4.6.3", | ||
"underscore": "1.13.3", | ||
"webpack": "5.72.0", | ||
"webpack-cli": "4.9.2", | ||
"webpack-dev-server": "4.8.1" | ||
"typedoc": "0.23.10", | ||
"typescript": "4.7.4", | ||
"underscore": "1.13.4", | ||
"webpack": "5.74.0", | ||
"webpack-cli": "4.10.0", | ||
"webpack-dev-server": "4.10.0" | ||
}, | ||
@@ -133,3 +134,3 @@ "homepage": "https://github.com/planttheidea/moize#readme", | ||
"types": "./index.d.ts", | ||
"version": "6.1.1" | ||
"version": "6.1.2" | ||
} |
@@ -42,2 +42,3 @@ > moize | ||
- [moize.maxSize](#moizemaxsize) | ||
- [moize.profile](#moizeprofile) | ||
- [moize.promise](#moizepromise) | ||
@@ -557,3 +558,3 @@ - [moize.react](#moizereact) | ||
_defaults to function name and file/line location_ | ||
_defaults to function name when it exists, or `Anonymous {count}` otherwise_ | ||
@@ -576,3 +577,3 @@ Name to use as unique identifier for the function when collecting statistics. | ||
**NOTE**: You must be collecting statistics for this option to take effect. | ||
**NOTE**: You must be collecting statistics for this option to provide value, as it is the identifier used for statistics collection. | ||
@@ -786,2 +787,16 @@ ## serializer | ||
## moize.profile | ||
Pre-applies the [`profileName`](#profilename) option as a curriable method. | ||
```ts | ||
import moize from 'moize'; | ||
const fn = (one: string, two: string) => `${one} ${two}`; | ||
export default moize.profile('my fancy identity')(fn); | ||
``` | ||
**NOTE**: You must be collecting statistics for this option to provide value, as it is the identifier used for statistics collection. | ||
## moize.promise | ||
@@ -1045,2 +1060,4 @@ | ||
**NOTE**: If collecting statistics, it is recommended to provide a custom [`profileName`](#profilename) or use [`moize.profile()`](#moizeprofile) for all memoized functions. This allows easier mapping of resulting statistics to their origin function when it has a common name or is anonymous. | ||
## getStats([profileName]) | ||
@@ -1047,0 +1064,0 @@ |
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
1347
742167
59
7750
Updatedmicro-memoize@^4.0.11