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.0-beta.4 to 6.0.0-beta.5

.prettierrc.js

4

CHANGELOG.md

@@ -7,8 +7,8 @@ # moize CHANGELOG

- By default, `moize` will now only keep a cache size of 1 instead of infinite. If you want to have history, it is recommended to use `moize.maxSize` to set the size of history desired, or for backwards compatibility use `moize.infinite`.
- `moize` v5 and below had a default cache size of `Infinity`, however starting with v6 the default cache size will be `1`. If you want to maintain a cache history of multiple entries, it is recommended to use `moize.maxSize` to set the size of history desired. To replicate usage from v5 and below, use `moize.infinite`.
- `isReact` option and `moize.react` shorthand method now memoizes on a per-instance basis (previously shared cache across all instances).
- `moize.simple` and `moize.reactSimple` have been removed due to default cache size being 1.
- `isSerialized` option and `moize.serialize` shorthand method will now serialize functions by default.
- `shouldSerializeFunctions` option has been removed, as serializing functions is now the default.
- `equals` option has been renamed to `matchesArg` for alignment with `matchesKey`.
- `shouldSerializeFunctions` option has been removed.

@@ -15,0 +15,0 @@ **ENHANCEMENTS**

'use strict';
function _interopDefault (ex) { return (ex && (typeof ex === 'object') && 'default' in ex) ? ex['default'] : ex; }
var memoize = _interopDefault(require('micro-memoize'));
var memoize = require('micro-memoize');
var fastEquals = require('fast-equals');
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var memoize__default = /*#__PURE__*/_interopDefaultLegacy(memoize);
function _extends() {

@@ -554,11 +556,3 @@ _extends = Object.assign || function (target) {

}
}); // for (const property in originalFn) {
// if (
// skippedProperties.indexOf(property) === -1 &&
// hasOwnProperty.call(originalFn, property)
// ) {
// newFn[property as keyof typeof newFn] =
// originalFn[property as keyof typeof originalFn];
// }
// }
});
}

@@ -782,2 +776,5 @@ /**

// 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;
/**

@@ -799,2 +796,3 @@ * @private

*/
function createMoizedComponent(moizer, fn, options) {

@@ -835,8 +833,14 @@ /**

// eslint-disable-next-line react/display-name
Moized.prototype.render = function () {
return this.MoizedComponent(this.props, this.context);
return {
$$typeof: REACT_ELEMENT_TYPE,
type: this.MoizedComponent,
props: this.props,
ref: null,
key: null,
_owner: null
};
};
copyStaticProperties(fn, Moized, ['contextType']);
copyStaticProperties(fn, Moized, ['contextType', 'contextTypes']);
Moized.displayName = "Moized(" + (fn.displayName || fn.name || 'Component') + ")";

@@ -1199,3 +1203,3 @@ return Moized;

var memoized = memoize(fn, microMemoizeOptions);
var memoized = memoize__default['default'](fn, microMemoizeOptions);
var moized = createMoizeInstance(memoized, {

@@ -1202,0 +1206,0 @@ expirations: expirations,

@@ -550,11 +550,3 @@ import memoize from 'micro-memoize';

}
}); // for (const property in originalFn) {
// if (
// skippedProperties.indexOf(property) === -1 &&
// hasOwnProperty.call(originalFn, property)
// ) {
// newFn[property as keyof typeof newFn] =
// originalFn[property as keyof typeof originalFn];
// }
// }
});
}

@@ -778,2 +770,5 @@ /**

// 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;
/**

@@ -795,2 +790,3 @@ * @private

*/
function createMoizedComponent(moizer, fn, options) {

@@ -831,8 +827,14 @@ /**

// eslint-disable-next-line react/display-name
Moized.prototype.render = function () {
return this.MoizedComponent(this.props, this.context);
return {
$$typeof: REACT_ELEMENT_TYPE,
type: this.MoizedComponent,
props: this.props,
ref: null,
key: null,
_owner: null
};
};
copyStaticProperties(fn, Moized, ['contextType']);
copyStaticProperties(fn, Moized, ['contextType', 'contextTypes']);
Moized.displayName = "Moized(" + (fn.displayName || fn.name || 'Component') + ")";

@@ -839,0 +841,0 @@ return Moized;

(function (global, factory) {
typeof exports === 'object' && typeof module !== 'undefined' ? module.exports = factory(require('micro-memoize'), require('fast-equals')) :
typeof define === 'function' && define.amd ? define(['micro-memoize', 'fast-equals'], factory) :
(global = global || self, global.moize = factory(global.memoize, global.fe));
(global = typeof globalThis !== 'undefined' ? globalThis : global || self, global.moize = factory(global.memoize, global.fe));
}(this, (function (memoize, fastEquals) { 'use strict';
memoize = memoize && Object.prototype.hasOwnProperty.call(memoize, 'default') ? memoize['default'] : memoize;
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
var memoize__default = /*#__PURE__*/_interopDefaultLegacy(memoize);
function _extends() {

@@ -555,11 +557,3 @@ _extends = Object.assign || function (target) {

}
}); // for (const property in originalFn) {
// if (
// skippedProperties.indexOf(property) === -1 &&
// hasOwnProperty.call(originalFn, property)
// ) {
// newFn[property as keyof typeof newFn] =
// originalFn[property as keyof typeof originalFn];
// }
// }
});
}

@@ -783,2 +777,5 @@ /**

// 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;
/**

@@ -800,2 +797,3 @@ * @private

*/
function createMoizedComponent(moizer, fn, options) {

@@ -836,8 +834,14 @@ /**

// eslint-disable-next-line react/display-name
Moized.prototype.render = function () {
return this.MoizedComponent(this.props, this.context);
return {
$$typeof: REACT_ELEMENT_TYPE,
type: this.MoizedComponent,
props: this.props,
ref: null,
key: null,
_owner: null
};
};
copyStaticProperties(fn, Moized, ['contextType']);
copyStaticProperties(fn, Moized, ['contextType', 'contextTypes']);
Moized.displayName = "Moized(" + (fn.displayName || fn.name || 'Component') + ")";

@@ -1200,3 +1204,3 @@ return Moized;

var memoized = memoize(fn, microMemoizeOptions);
var memoized = memoize__default['default'](fn, microMemoizeOptions);
var moized = createMoizeInstance(memoized, {

@@ -1203,0 +1207,0 @@ expirations: expirations,

@@ -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=e||self).moize=n(e.memoize,e.fe)}(this,(function(e,n){"use strict";function t(){return(t=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)}e=e&&Object.prototype.hasOwnProperty.call(e,"default")?e.default:e;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){var r=a(e,n);-1!==r&&(clearTimeout(e[r].timeoutId),t&&e.splice(r,1))}function f(e,n){var t=setTimeout(e,n);return"function"==typeof t.unref&&t.unref(),t}function l(e,n){return function(t){var r=t.keys[0],i=a(e,r);~i&&(c(e,r,!1),e[i].timeoutId=f(e[i].expirationMethod,n.maxAge))}}function p(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,l,p){var h=s.keys[0];if(-1===a(e,h)){var m=function(){var i=u(t,r)(s.keys,h),a=s.values[i];~i&&(s.keys.splice(i,1),s.values.splice(i,1),"function"==typeof n.onCacheChange&&n.onCacheChange(s,l,p)),c(e,h,!0),"function"==typeof n.onExpire&&!1===n.onExpire(h)&&(s.keys.unshift(h),s.values.unshift(a),o(s,l,p),"function"==typeof n.onCacheChange&&n.onCacheChange(s,l,p))};e.push({expirationMethod:m,key:h,timeoutId:f(m,i)})}}}(e,n,t,r):void 0;return{onCacheAdd:i,onCacheHit:i&&n.updateExpire?l(e,n):void 0}}var h={anonymousProfileNameCounter:1,isCollectingStats:!1,profiles:{}},m=!1;function g(e){e?delete h.profiles[e]:h.profiles={}}function y(e){var n=e.profileName;return function(){n&&!h.profiles[n]&&(h.profiles[n]={calls:0,hits:0}),h.profiles[n].calls++}}function d(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 v(e){var n=(new Error).stack,t=e.displayName||e.name||"Anonymous "+h.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 x(e,n){return e?(n/e*100).toFixed(4)+"%":"0.0000%"}function C(e){h.isCollectingStats||m||(console.warn('Stats are not currently being collected, please run "collectStats" to enable them.'),m=!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:x(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]=C(n),e}),{}),usage:x(i.calls,i.hits)})}var A={constructor:!0,length:!0,name:!0,prototype:!0};function z(e,n,t){void 0===t&&(t=[]),Object.getOwnPropertyNames(e).forEach((function(r){if(!A[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 S(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(){g(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 C(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 f=u.keys[s];return u.keys.splice(s,1),u.values.splice(s,1),r&&r(u,o.options,o),c(t,f,!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 h=r.keys[l];r.values[l]=n,l>0&&r.orderByLru(h,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}}}),z(i,e)}(e,n),e}function E(e,n){for(var t=e.length,r=0;r<t;++r)if(e[r]===n)return r+1;return 0}function b(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=E(n,this);0===o?n[n.length]=this:(n.splice(o),t.splice(o)),t[t.length]=e;var a=E(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+=b(e[t])+"|";return[n]}function O(e,n){return e[0]===n[0]}function q(e){if("function"==typeof e)return function(n,t,r){return e(r.cache,r.options,r)}}function K(e){return o(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 N=function o(a,u){var c=u||r;if(function(e){return"function"==typeof e&&e.isMoized}(a)){var f=a.originalFunction,l=s(a.options,c);return o(f,l)}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(c.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 this.MoizedComponent(this.props,this.context)},z(n,o,["contextType"]),o.displayName="Moized("+(n.displayName||n.name||"Component")+")",o}(o,a,c);var m=t({},r,c,{maxAge:"number"==typeof c.maxAge&&c.maxAge>=0?c.maxAge:r.maxAge,maxArgs:"number"==typeof c.maxArgs&&c.maxArgs>=0?c.maxArgs:r.maxArgs,maxSize:"number"==typeof c.maxSize&&c.maxSize>=0?c.maxSize:r.maxSize,profileName:c.profileName||v(a)}),g=[],x=(m.matchesArg,m.isDeepEqual,m.isPromise),C=(m.isReact,m.isSerialized,m.isShallowEqual,m.matchesKey,m.maxAge,m.maxArgs,m.maxSize),A=m.onCacheAdd,E=m.onCacheChange,b=m.onCacheHit,k=(m.onExpire,m.profileName,m.serializer,m.updateCacheForKey),N=(m.transformArgs,m.updateExpire,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,["matchesArg","isDeepEqual","isPromise","isReact","isSerialized","isShallowEqual","matchesKey","maxAge","maxArgs","maxSize","onCacheAdd","onCacheChange","onCacheHit","onExpire","profileName","serializer","updateCacheForKey","transformArgs","updateExpire"])),w=function(e){return e.matchesArg||e.isDeepEqual&&n.deepEqual||e.isShallowEqual&&n.shallowEqual||n.sameValueZeroEqual}(m),M=function(e){return e.matchesKey||e.isSerialized&&O||void 0}(m),j=p(g,m,w,M),P=function(e){return h.isCollectingStats?{onCacheAdd:y(e),onCacheHit:d(e)}:{}}(m),F=K(m),H=t({},N,{isEqual:w,isMatchingKey:M,isPromise:x,maxSize:C,onCacheAdd:q(i(A,j.onCacheAdd,P.onCacheAdd)),onCacheChange:q(E),onCacheHit:q(i(b,j.onCacheHit,P.onCacheHit)),transformKey:F}),R=S(e(a,H),{expirations:g,options:m,originalFunction:a});return k?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 z(e,t),t}(R):R};return N.clearStats=g,N.collectStats=function(e){void 0===e&&(e=!0),h.isCollectingStats=e},N.compose=function(){return o.apply(void 0,arguments)||N},N.deep=N({isDeepEqual:!0}),N.getStats=C,N.infinite=N({maxSize:1/0}),N.isCollectingStats=function(){return h.isCollectingStats},N.isMoized=function(e){return"function"==typeof e&&!!e.isMoized},N.matchesArg=function(e){return N({matchesArg:e})},N.matchesKey=function(e){return N({matchesKey:e})},N.maxAge=function(e,n){if(!0===n)return N({maxAge:e,updateExpire:n});if("object"==typeof n){var t=n.onExpire,r=n.updateExpire;return N({maxAge:e,onExpire:t,updateExpire:r})}return N("function"==typeof n?{maxAge:e,onExpire:n,updateExpire:!0}:{maxAge:e})},N.maxArgs=function(e){return N({maxArgs:e})},N.maxSize=function(e){return N({maxSize:e})},N.profile=function(e){return N({profileName:e})},N.promise=N({isPromise:!0,updateExpire:!0}),N.react=N({isReact:!0}),N.serialize=N({isSerialized:!0}),N.serializeWith=function(e){return N({isSerialized:!0,serializer:e})},N.shallow=N({isShallowEqual:!0}),N.transformArgs=function(e){return N({transformArgs:e})},N.updateCacheForKey=function(e){return N({updateCacheForKey:e})},N}));
!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={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 M(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 j=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=[],y=(p.matchesArg,p.isDeepEqual,p.isPromise),d=(p.isReact,p.isSerialized,p.isShallowEqual,p.matchesKey,p.maxAge,p.maxArgs,p.maxSize),A=p.onCacheAdd,z=p.onCacheChange,S=p.onCacheHit,O=(p.onExpire,p.profileName,p.serializer,p.updateCacheForKey),q=(p.transformArgs,p.updateExpire,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),j=function(e){return e.matchesKey||e.isSerialized&&N||void 0}(p),P=h(m,p,K,j),F=function(e){return g.isCollectingStats?{onCacheAdd:v(e),onCacheHit:x(e)}:{}}(p),H=M(p),R=i({},q,{isEqual:K,isMatchingKey:j,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 j.clearStats=d,j.collectStats=function(e){void 0===e&&(e=!0),g.isCollectingStats=e},j.compose=function(){return u.apply(void 0,arguments)||j},j.deep=j({isDeepEqual:!0}),j.getStats=z,j.infinite=j({maxSize:1/0}),j.isCollectingStats=function(){return g.isCollectingStats},j.isMoized=function(e){return"function"==typeof e&&!!e.isMoized},j.matchesArg=function(e){return j({matchesArg:e})},j.matchesKey=function(e){return j({matchesKey:e})},j.maxAge=function(e,n){if(!0===n)return j({maxAge:e,updateExpire:n});if("object"==typeof n){var t=n.onExpire,r=n.updateExpire;return j({maxAge:e,onExpire:t,updateExpire:r})}return j("function"==typeof n?{maxAge:e,onExpire:n,updateExpire:!0}:{maxAge:e})},j.maxArgs=function(e){return j({maxArgs:e})},j.maxSize=function(e){return j({maxSize:e})},j.profile=function(e){return j({profileName:e})},j.promise=j({isPromise:!0,updateExpire:!0}),j.react=j({isReact:!0}),j.serialize=j({isSerialized:!0}),j.serializeWith=function(e){return j({isSerialized:!0,serializer:e})},j.shallow=j({isShallowEqual:!0}),j.transformArgs=function(e){return j({transformArgs:e})},j.updateCacheForKey=function(e){return j({updateCacheForKey:e})},j}));
//# sourceMappingURL=moize.min.js.map

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

"devDependencies": {
"@babel/cli": "7.10.3",
"@babel/core": "7.10.3",
"@babel/plugin-proposal-class-properties": "7.10.1",
"@babel/preset-env": "7.10.3",
"@babel/preset-react": "7.10.1",
"@babel/preset-typescript": "7.10.1",
"@rollup/plugin-babel": "5.0.4",
"@rollup/plugin-commonjs": "13.0.0",
"@rollup/plugin-node-resolve": "8.1.0",
"@babel/cli": "7.11.6",
"@babel/core": "7.11.6",
"@babel/plugin-proposal-class-properties": "7.10.4",
"@babel/preset-env": "7.11.5",
"@babel/preset-react": "7.10.4",
"@babel/preset-typescript": "7.10.4",
"@rollup/plugin-babel": "5.2.1",
"@rollup/plugin-commonjs": "15.1.0",
"@rollup/plugin-node-resolve": "9.0.0",
"@types/bluebird": "3.5.32",
"@types/jest": "26.0.3",
"@types/lodash": "4.14.157",
"@types/jest": "26.0.14",
"@types/lodash": "4.14.161",
"@types/memoizee": "0.4.4",
"@types/react": "16.9.41",
"@types/react": "16.9.50",
"@types/react-dom": "16.9.8",
"@typescript-eslint/eslint-plugin": "3.4.0",
"@typescript-eslint/parser": "3.4.0",
"@typescript-eslint/eslint-plugin": "4.3.0",
"@typescript-eslint/parser": "4.3.0",
"babel-eslint": "10.1.0",
"babel-jest": "26.1.0",
"babel-jest": "26.3.0",
"babel-loader": "8.1.0",

@@ -46,37 +46,37 @@ "benchmark": "2.1.4",

"core-js": "3.6.5",
"eslint": "7.3.1",
"eslint": "7.10.0",
"eslint-friendly-formatter": "4.0.1",
"eslint-loader": "4.0.2",
"eslint-plugin-react": "7.20.1",
"eslint-plugin-react": "7.21.3",
"fast-memoize": "2.5.2",
"fs-extra": "9.0.1",
"html-webpack-plugin": "4.3.0",
"husky": "4.2.5",
"html-webpack-plugin": "4.5.0",
"husky": "4.3.0",
"in-publish": "2.0.1",
"ink-docstrap": "1.3.2",
"jest": "26.1.0",
"jsdoc": "3.6.4",
"jest": "26.4.2",
"jsdoc": "3.6.6",
"jsdoc-babel": "0.5.0",
"jsdom": "16.2.2",
"jsdom": "16.4.0",
"jsdom-global": "3.0.2",
"lodash": "4.17.15",
"lodash": "4.17.20",
"lru-memoize": "1.1.0",
"mem": "6.1.0",
"mem": "7.0.0-1",
"memoizee": "0.4.14",
"memoizerific": "1.11.3",
"ora": "4.0.4",
"ora": "5.1.0",
"prop-types": "15.7.2",
"q": "1.5.1",
"ramda": "0.27.0",
"ramda": "0.27.1",
"react": "16.13.1",
"react-dom": "16.13.1",
"regenerator-runtime": "0.13.5",
"regenerator-runtime": "0.13.7",
"rimraf": "3.0.2",
"rollup": "2.18.1",
"rollup-plugin-terser": "6.1.0",
"tslib": "2.0.0",
"typedoc": "0.17.8",
"typescript": "3.9.5",
"underscore": "1.10.2",
"webpack": "4.43.0",
"rollup": "2.28.2",
"rollup-plugin-terser": "7.0.2",
"tslib": "2.0.1",
"typedoc": "0.19.2",
"typescript": "4.0.3",
"underscore": "1.11.0",
"webpack": "4.44.2",
"webpack-cli": "3.3.12",

@@ -140,3 +140,3 @@ "webpack-dev-server": "3.11.0"

"types": "./index.d.ts",
"version": "6.0.0-beta.4"
"version": "6.0.0-beta.5"
}

@@ -187,2 +187,4 @@ > moize

All default values can be found [here](src/constants.ts).
## isDeepEqual

@@ -313,3 +315,3 @@

const memoized = moize(fn, { isDeepEqual: true });
const memoized = moize(fn, { isShallowEqual: true });

@@ -436,3 +438,3 @@ memoized({ one: 'one', two: 'two' });

_defaults to Infinity_
_defaults to 1_

@@ -439,0 +441,0 @@ The maximum number of values you want stored in cache for this method. Clearance of the cache once the `maxSize` is reached is on a [Least Recently Used](https://en.wikipedia.org/wiki/Cache_replacement_policies#Least_Recently_Used_.28LRU.29) basis.

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