Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

moize

Package Overview
Dependencies
Maintainers
2
Versions
104
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

moize - npm Package Compare versions

Comparing version 6.0.3 to 6.1.0

30

__tests__/default.ts

@@ -349,6 +349,4 @@ import { sameValueZeroEqual } from 'fast-equals';

const { isEqual, ...options } = memoized._microMemoizeOptions;
const {
isEqual: _isEqualIgnored,
...resultOptions
} = mmResult.options;
const { isEqual: _isEqualIgnored, ...resultOptions } =
mmResult.options;

@@ -413,3 +411,27 @@ expect(options).toEqual(resultOptions);

});
it('should prefer the `profileName` when provided', () => {
function myNamedFunction() {}
const memoized = moize(myNamedFunction, {
profileName: 'custom profile name',
});
expect(memoized.name).toBe('moized(custom profile name)');
});
it('should wrap the original function name', () => {
function myNamedFunction() {}
const memoized = moize(myNamedFunction);
expect(memoized.name).toBe('moized(myNamedFunction)');
});
it('should have an ultimate fallback for an anonymous function', () => {
const memoized = moize(() => {});
expect(memoized.name).toBe('moized(anonymous)');
});
});
});

@@ -321,2 +321,14 @@ import moize from '../src';

});
describe('edge cases', () => {
it('should retain the original function name', () => {
function myNamedFunction() {}
const memoized = moize(myNamedFunction, {
updateCacheForKey: () => false,
});
expect(memoized.name).toBe('moized(myNamedFunction)');
});
});
});
# moize CHANGELOG
## 6.1.0
- [#161](https://github.com/planttheidea/moize/issues/161) - Provide custom function name when supported
## 6.0.3

@@ -4,0 +8,0 @@

25

dist/moize.cjs.js

@@ -194,2 +194,14 @@ 'use strict';

}
function setName(fn, originalFunctionName, profileName) {
try {
var name = profileName || originalFunctionName || 'anonymous';
Object.defineProperty(fn, 'name', {
configurable: true,
enumerable: false,
value: "moized(" + name + ")",
writable: true
});
} catch (_unused) {// For engines where `function.name` is not configurable, do nothing.
}
}

@@ -779,4 +791,4 @@ /**

// This was stolen from React internals, which allows us to create React elements without needing
// a dependency on the React library itself.
var REACT_ELEMENT_TYPE = typeof Symbol === 'function' && Symbol.for ? Symbol.for('react.element') : 0xeac7;

@@ -848,2 +860,3 @@ /**

Moized.displayName = "Moized(" + (fn.displayName || fn.name || 'Component') + ")";
setName(Moized, fn.name, options.profileName);
return Moized;

@@ -1086,3 +1099,3 @@ }

function refreshableMoized() {
var refreshableMoized = function refreshableMoized() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {

@@ -1099,3 +1112,3 @@ args[_key] = arguments[_key];

return result;
}
};

@@ -1106,2 +1119,3 @@ copyStaticProperties(moized, refreshableMoized);

var _excluded = ["matchesArg", "isDeepEqual", "isPromise", "isReact", "isSerialized", "isShallowEqual", "matchesKey", "maxAge", "maxArgs", "maxSize", "onCacheAdd", "onCacheChange", "onCacheHit", "onExpire", "profileName", "serializer", "updateCacheForKey", "transformArgs", "updateExpire"];
/**

@@ -1189,3 +1203,3 @@ * @module moize

coalescedOptions.updateExpire;
var customOptions = _objectWithoutPropertiesLoose(coalescedOptions, ["matchesArg", "isDeepEqual", "isPromise", "isReact", "isSerialized", "isShallowEqual", "matchesKey", "maxAge", "maxArgs", "maxSize", "onCacheAdd", "onCacheChange", "onCacheHit", "onExpire", "profileName", "serializer", "updateCacheForKey", "transformArgs", "updateExpire"]);
var customOptions = _objectWithoutPropertiesLoose(coalescedOptions, _excluded);

@@ -1217,5 +1231,6 @@ var isEqual = getIsEqual(coalescedOptions);

if (updateCacheForKey) {
return createRefreshableMoized(moized);
moized = createRefreshableMoized(moized);
}
setName(moized, fn.name, options.profileName);
return moized;

@@ -1222,0 +1237,0 @@ };

@@ -188,2 +188,14 @@ import memoize from 'micro-memoize';

}
function setName(fn, originalFunctionName, profileName) {
try {
var name = profileName || originalFunctionName || 'anonymous';
Object.defineProperty(fn, 'name', {
configurable: true,
enumerable: false,
value: "moized(" + name + ")",
writable: true
});
} catch (_unused) {// For engines where `function.name` is not configurable, do nothing.
}
}

@@ -773,4 +785,4 @@ /**

// This was stolen from React internals, which allows us to create React elements without needing
// a dependency on the React library itself.
var REACT_ELEMENT_TYPE = typeof Symbol === 'function' && Symbol.for ? Symbol.for('react.element') : 0xeac7;

@@ -842,2 +854,3 @@ /**

Moized.displayName = "Moized(" + (fn.displayName || fn.name || 'Component') + ")";
setName(Moized, fn.name, options.profileName);
return Moized;

@@ -1080,3 +1093,3 @@ }

function refreshableMoized() {
var refreshableMoized = function refreshableMoized() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {

@@ -1093,3 +1106,3 @@ args[_key] = arguments[_key];

return result;
}
};

@@ -1100,2 +1113,3 @@ copyStaticProperties(moized, refreshableMoized);

var _excluded = ["matchesArg", "isDeepEqual", "isPromise", "isReact", "isSerialized", "isShallowEqual", "matchesKey", "maxAge", "maxArgs", "maxSize", "onCacheAdd", "onCacheChange", "onCacheHit", "onExpire", "profileName", "serializer", "updateCacheForKey", "transformArgs", "updateExpire"];
/**

@@ -1183,3 +1197,3 @@ * @module moize

coalescedOptions.updateExpire;
var customOptions = _objectWithoutPropertiesLoose(coalescedOptions, ["matchesArg", "isDeepEqual", "isPromise", "isReact", "isSerialized", "isShallowEqual", "matchesKey", "maxAge", "maxArgs", "maxSize", "onCacheAdd", "onCacheChange", "onCacheHit", "onExpire", "profileName", "serializer", "updateCacheForKey", "transformArgs", "updateExpire"]);
var customOptions = _objectWithoutPropertiesLoose(coalescedOptions, _excluded);

@@ -1211,5 +1225,6 @@ var isEqual = getIsEqual(coalescedOptions);

if (updateCacheForKey) {
return createRefreshableMoized(moized);
moized = createRefreshableMoized(moized);
}
setName(moized, fn.name, options.profileName);
return moized;

@@ -1600,3 +1615,3 @@ };

export default moize;
export { moize as default };
//# sourceMappingURL=moize.esm.js.map

@@ -195,2 +195,14 @@ (function (global, factory) {

}
function setName(fn, originalFunctionName, profileName) {
try {
var name = profileName || originalFunctionName || 'anonymous';
Object.defineProperty(fn, 'name', {
configurable: true,
enumerable: false,
value: "moized(" + name + ")",
writable: true
});
} catch (_unused) {// For engines where `function.name` is not configurable, do nothing.
}
}

@@ -780,4 +792,4 @@ /**

// This was stolen from React internals, which allows us to create React elements without needing
// a dependency on the React library itself.
var REACT_ELEMENT_TYPE = typeof Symbol === 'function' && Symbol.for ? Symbol.for('react.element') : 0xeac7;

@@ -849,2 +861,3 @@ /**

Moized.displayName = "Moized(" + (fn.displayName || fn.name || 'Component') + ")";
setName(Moized, fn.name, options.profileName);
return Moized;

@@ -1087,3 +1100,3 @@ }

function refreshableMoized() {
var refreshableMoized = function refreshableMoized() {
for (var _len = arguments.length, args = new Array(_len), _key = 0; _key < _len; _key++) {

@@ -1100,3 +1113,3 @@ args[_key] = arguments[_key];

return result;
}
};

@@ -1107,2 +1120,3 @@ copyStaticProperties(moized, refreshableMoized);

var _excluded = ["matchesArg", "isDeepEqual", "isPromise", "isReact", "isSerialized", "isShallowEqual", "matchesKey", "maxAge", "maxArgs", "maxSize", "onCacheAdd", "onCacheChange", "onCacheHit", "onExpire", "profileName", "serializer", "updateCacheForKey", "transformArgs", "updateExpire"];
/**

@@ -1190,3 +1204,3 @@ * @module moize

coalescedOptions.updateExpire;
var customOptions = _objectWithoutPropertiesLoose(coalescedOptions, ["matchesArg", "isDeepEqual", "isPromise", "isReact", "isSerialized", "isShallowEqual", "matchesKey", "maxAge", "maxArgs", "maxSize", "onCacheAdd", "onCacheChange", "onCacheHit", "onExpire", "profileName", "serializer", "updateCacheForKey", "transformArgs", "updateExpire"]);
var customOptions = _objectWithoutPropertiesLoose(coalescedOptions, _excluded);

@@ -1218,5 +1232,6 @@ var isEqual = getIsEqual(coalescedOptions);

if (updateCacheForKey) {
return createRefreshableMoized(moized);
moized = createRefreshableMoized(moized);
}
setName(moized, fn.name, options.profileName);
return moized;

@@ -1223,0 +1238,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}).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){var r=s(e,n);-1!==r&&(clearTimeout(e[r].timeoutId),t&&e.splice(r,1))}function p(e,n){var t=setTimeout(e,n);return"function"==typeof t.unref&&t.unref(),t}function m(e,n){return function(t){var r=t.keys[0],i=s(e,r);~i&&(l(e,r,!1),e[i].timeoutId=p(e[i].expirationMethod,n.maxAge))}}function h(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 m=a.keys[0];if(-1===s(e,m)){var h=function(){var i=c(t,r)(a.keys,m),s=a.values[i];~i&&(a.keys.splice(i,1),a.values.splice(i,1),"function"==typeof n.onCacheChange&&n.onCacheChange(a,u,f)),l(e,m,!0),"function"==typeof n.onExpire&&!1===n.onExpire(m)&&(a.keys.unshift(m),a.values.unshift(s),o(a,u,f),"function"==typeof n.onCacheChange&&n.onCacheChange(a,u,f))};e.push({expirationMethod:h,key:m,timeoutId:p(h,i)})}}}(e,n,t,r):void 0;return{onCacheAdd:i,onCacheHit:i&&n.updateExpire?m(e,n):void 0}}var g={anonymousProfileNameCounter:1,isCollectingStats:!1,profiles:{}},y=!1;function d(e){e?delete g.profiles[e]:g.profiles={}}function v(e){var n=e.profileName;return function(){n&&!g.profiles[n]&&(g.profiles[n]={calls:0,hits:0}),g.profiles[n].calls++}}function x(e){return function(){var n=g.profiles,t=e.profileName;n[t]||(n[t]={calls:0,hits:0}),n[t].calls++,n[t].hits++}}function C(e){var n=(new Error).stack,t=e.displayName||e.name||"Anonymous "+g.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 A(e,n){return e?(n/e*100).toFixed(4)+"%":"0.0000%"}function z(e){g.isCollectingStats||y||(console.warn('Stats are not currently being collected, please run "collectStats" to enable them.'),y=!0);var n=g.profiles;if(e){if(!n[e])return{calls:0,hits:0,usage:"0.0000%"};var t=n[e];return i({},t,{usage:A(t.calls,t.hits)})}var r=Object.keys(g.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]=z(n),e}),{}),usage:A(r.calls,r.hits)})}var S={arguments:!0,callee:!0,caller:!0,constructor:!0,length:!0,name:!0,prototype:!0};function b(e,n,t){void 0===t&&(t=[]),Object.getOwnPropertyNames(e).forEach((function(r){if(!S[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 E(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(){d(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 z(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),l(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}}}),b(i,e)}(e,n),e}var k="function"==typeof Symbol&&Symbol.for?Symbol.for("react.element"):60103;function O(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=O(n,this);0===o?n[n.length]=this:(n.splice(o),t.splice(o)),t[t.length]=e;var a=O(n,r);if(0!==a)return"[ref="+(t.slice(0,a).join(".")||".")+"]"}else n[0]=r,t[0]=e;return r}return""+r}))}function K(e){for(var n="|",t=0;t<e.length;t++)n+=q(e[t])+"|";return[n]}function N(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 j(e){return u(e.isSerialized&&function(e){return"function"==typeof e.serializer?e.serializer:K}(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 M=function e(t,u){var s=u||o;if(function(e){return"function"==typeof e&&e.isMoized}(t)){var c=t.originalFunction,l=f(t.options,s);return e(c,l)}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:k,type:this.MoizedComponent,props:this.props,ref:null,key:null,_owner:null}},b(n,o,["contextType","contextTypes"]),o.displayName="Moized("+(n.displayName||n.name||"Component")+")",o}(e,t,s);var p=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||C(t)}),m=[];p.matchesArg,p.isDeepEqual;var y=p.isPromise;p.isReact,p.isSerialized,p.isShallowEqual,p.matchesKey,p.maxAge,p.maxArgs;var d=p.maxSize,A=p.onCacheAdd,z=p.onCacheChange,S=p.onCacheHit;p.onExpire,p.profileName,p.serializer;var O=p.updateCacheForKey;p.transformArgs,p.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}(p,["matchesArg","isDeepEqual","isPromise","isReact","isSerialized","isShallowEqual","matchesKey","maxAge","maxArgs","maxSize","onCacheAdd","onCacheChange","onCacheHit","onExpire","profileName","serializer","updateCacheForKey","transformArgs","updateExpire"]),K=function(e){return e.matchesArg||e.isDeepEqual&&n.deepEqual||e.isShallowEqual&&n.shallowEqual||n.sameValueZeroEqual}(p),M=function(e){return e.matchesKey||e.isSerialized&&N||void 0}(p),P=h(m,p,K,M),F=function(e){return g.isCollectingStats?{onCacheAdd:v(e),onCacheHit:x(e)}:{}}(p),H=j(p),R=i({},q,{isEqual:K,isMatchingKey:M,isPromise:y,maxSize:d,onCacheAdd:w(a(A,P.onCacheAdd,F.onCacheAdd)),onCacheChange:w(z),onCacheHit:w(a(S,P.onCacheHit,F.onCacheHit)),transformKey:H}),_=E(r.default(t,R),{expirations:m,options:p,originalFunction:t});return O?function(e){var n=e.options.updateCacheForKey;function t(){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 b(e,t),t}(_):_};return M.clearStats=d,M.collectStats=function(e){void 0===e&&(e=!0),g.isCollectingStats=e},M.compose=function(){return u.apply(void 0,arguments)||M},M.deep=M({isDeepEqual:!0}),M.getStats=z,M.infinite=M({maxSize:1/0}),M.isCollectingStats=function(){return g.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}));
!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}).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}));
//# sourceMappingURL=moize.min.js.map
module.exports = {
coveragePathIgnorePatterns: ['node_modules', 'src/types.ts'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
roots: ['<rootDir>'],
setupFiles: ['<rootDir>/jest.init.js'],
transform: {
'\\.(js|ts|tsx)$': 'babel-jest',
},
testRegex: '/__tests__/.*\\.(ts|tsx|js)$',
verbose: true,
coveragePathIgnorePatterns: ['node_modules', 'src/types.ts'],
moduleFileExtensions: ['ts', 'tsx', 'js', 'jsx', 'json', 'node'],
roots: ['<rootDir>'],
setupFiles: ['<rootDir>/jest.init.js'],
testEnvironment: 'jsdom',
testRegex: '/__tests__/.*\\.(ts|tsx|js)$',
transform: {
'\\.(js|ts|tsx)$': 'babel-jest',
},
verbose: true,
};

@@ -21,21 +21,21 @@ {

"devDependencies": {
"@babel/cli": "7.13.16",
"@babel/core": "7.13.16",
"@babel/plugin-proposal-class-properties": "7.13.0",
"@babel/preset-env": "7.13.15",
"@babel/preset-react": "7.13.13",
"@babel/preset-typescript": "7.13.0",
"@babel/cli": "7.14.8",
"@babel/core": "7.15.0",
"@babel/plugin-proposal-class-properties": "7.14.5",
"@babel/preset-env": "7.15.0",
"@babel/preset-react": "7.14.5",
"@babel/preset-typescript": "7.15.0",
"@rollup/plugin-babel": "5.3.0",
"@rollup/plugin-commonjs": "18.0.0",
"@rollup/plugin-node-resolve": "11.2.1",
"@types/bluebird": "3.5.33",
"@types/jest": "26.0.22",
"@types/lodash": "4.14.168",
"@types/memoizee": "0.4.5",
"@types/react": "17.0.3",
"@types/react-dom": "17.0.3",
"@typescript-eslint/eslint-plugin": "4.22.0",
"@typescript-eslint/parser": "4.22.0",
"@rollup/plugin-commonjs": "20.0.0",
"@rollup/plugin-node-resolve": "13.0.4",
"@types/bluebird": "3.5.36",
"@types/jest": "27.0.1",
"@types/lodash": "4.14.172",
"@types/memoizee": "0.4.6",
"@types/react": "17.0.19",
"@types/react-dom": "17.0.9",
"@typescript-eslint/eslint-plugin": "4.29.3",
"@typescript-eslint/parser": "4.29.3",
"babel-eslint": "10.1.0",
"babel-jest": "26.6.3",
"babel-jest": "27.1.0",
"babel-loader": "8.2.2",

@@ -45,18 +45,14 @@ "benchmark": "2.1.4",

"cli-table2": "0.2.0",
"core-js": "3.11.0",
"eslint": "7.25.0",
"core-js": "3.16.4",
"eslint": "7.32.0",
"eslint-friendly-formatter": "4.0.1",
"eslint-loader": "4.0.2",
"eslint-plugin-react": "7.23.2",
"eslint-plugin-react": "7.25.0",
"fast-memoize": "2.5.2",
"fs-extra": "9.1.0",
"html-webpack-plugin": "5.3.1",
"husky": "6.0.0",
"html-webpack-plugin": "5.3.2",
"in-publish": "2.0.1",
"ink-docstrap": "1.3.2",
"jest": "26.6.3",
"jsdoc": "3.6.6",
"jest": "27.1.0",
"jsdoc": "3.6.7",
"jsdoc-babel": "0.5.0",
"jsdom": "16.5.3",
"jsdom-global": "3.0.2",
"lodash": "4.17.21",

@@ -67,3 +63,3 @@ "lru-memoize": "1.1.0",

"memoizerific": "1.11.3",
"ora": "5.4.0",
"ora": "5.4.1",
"prop-types": "15.7.2",

@@ -74,13 +70,13 @@ "q": "1.5.1",

"react-dom": "17.0.2",
"regenerator-runtime": "0.13.7",
"regenerator-runtime": "0.13.9",
"rimraf": "3.0.2",
"rollup": "2.45.2",
"rollup": "2.56.3",
"rollup-plugin-terser": "7.0.2",
"tslib": "2.2.0",
"typedoc": "0.20.36",
"typescript": "4.2.4",
"tslib": "2.3.1",
"typedoc": "0.21.8",
"typescript": "4.3.5",
"underscore": "1.13.1",
"webpack": "5.35.1",
"webpack-cli": "4.6.0",
"webpack-dev-server": "3.11.2"
"webpack": "5.51.1",
"webpack-cli": "4.8.0",
"webpack-dev-server": "4.0.0"
},

@@ -136,3 +132,3 @@ "homepage": "https://github.com/planttheidea/moize#readme",

"types": "./index.d.ts",
"version": "6.0.3"
"version": "6.1.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

Sorry, the diff of this file is not supported yet

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc