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

micro-memoize

Package Overview
Dependencies
Maintainers
1
Versions
68
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

micro-memoize - npm Package Compare versions

Comparing version 1.6.2 to 1.6.3

4

CHANGELOG.md
# micro-memoize CHANGELOG
## 1.6.3
* Replace native `slice` usages with `cloneArray` utility
## 1.6.2

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

41

dist/micro-memoize.js

@@ -7,2 +7,24 @@ (function (global, factory) {

/**
* @function cloneArray
*
* @description
* clone the array-like object and return the new array
*
* @param {Array<any>|Arguments} arrayLike the array-like object to clone
* @returns {Array<any>} the clone of the array
*/
var cloneArray = function cloneArray(arrayLike) {
var array = new Array(arrayLike.length);
for (var index = 0; index < arrayLike.length; index++) {
array[index] = arrayLike[index];
}
return array;
};
// types
var createAreKeysEqual = function createAreKeysEqual(isEqual) {

@@ -34,5 +56,2 @@ /**

// types
var createGetKeyIndex = function createGetKeyIndex(isEqual) {

@@ -143,7 +162,2 @@ var areKeysEqual = createAreKeysEqual(isEqual);

// types
var slice = [].slice;
/**

@@ -161,2 +175,5 @@ * @function memoize

*/
// types
function memoize(fn, options) {

@@ -211,3 +228,3 @@ // if it is a memoized method, don't re-memoize it

function memoized() {
var args = getTransformedKey ? getTransformedKey(slice.call(arguments, 0)) : arguments;
var args = getTransformedKey ? getTransformedKey(cloneArray(arguments)) : arguments;
var keyIndex = getKeyIndex(cache.keys, args);

@@ -230,3 +247,3 @@

orderByLru(cache.keys, getTransformedKey ? args : slice.call(args, 0), cache.keys.length);
orderByLru(cache.keys, getTransformedKey ? args : cloneArray(args), cache.keys.length);
orderByLru(cache.values, fn.apply(this, arguments), cache.values.length);

@@ -256,4 +273,4 @@

return {
keys: cache.keys.slice(0),
values: cache.values.slice(0)
keys: cloneArray(cache.keys),
values: cloneArray(cache.values)
};

@@ -260,0 +277,0 @@ }

@@ -1,1 +0,1 @@

!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(e.memoize={})}(this,function(e){"use strict";var n=function(e){var n=function(e){return function(n,r){if(n.length!==r.length)return!1;for(var t=0;t<n.length;t++)if(!e(n[t],r[t]))return!1;return!0}}(e);return function(e,r){for(var t=0;t<e.length;t++)if(n(e[t],r))return t;return-1}},r=function(e){return function(n){var r=e(n);return Array.isArray(r)?r:[r]}},t=function(e,n){return e===n||e!=e&&n!=n},i=function(e,n){},o=function(e,n,r){for(var t=r;t--;)e[t+1]=e[t];e[0]=n},u=function(e,n,r){e.values[0]=e.values[0].catch(function(t){var i=r(e.keys,n);throw~i&&(e.keys.splice(i,1),e.values.splice(i,1)),t})};var a=[].slice;e.default=function(e,s){if(e.isMemoized)return e;var c=s||{},f=c.isEqual,l=void 0===f?t:f,v=c.isPromise,h=void 0!==v&&v,d=c.maxSize,y=void 0===d?1:d,p=c.onCacheAdd,g=void 0===p?i:p,m=c.onCacheChange,k=void 0===m?i:m,C=c.onCacheHit,b=void 0===C?i:C,x=c.transformKey,z=function(e,n){var r={};for(var t in e)n.indexOf(t)>=0||Object.prototype.hasOwnProperty.call(e,t)&&(r[t]=e[t]);return r}(c,["isEqual","isPromise","maxSize","onCacheAdd","onCacheChange","onCacheHit","transformKey"]),O=Object.assign({},z,{isEqual:l,isPromise:h,maxSize:y,onCacheAdd:g,onCacheChange:k,onCacheHit:b,transformKey:x}),P=n(l),j=x?r(x):null,A={keys:[],values:[]};function S(){var n=j?j(a.call(arguments,0)):arguments,r=P(A.keys,n);return~r?(b(A,O),r&&(o(A.keys,A.keys[r],r),o(A.values,A.values[r],r),k(A,O))):(A.keys.length>=y&&(A.keys.pop(),A.values.pop()),o(A.keys,j?n:a.call(n,0),A.keys.length),o(A.values,e.apply(this,arguments),A.values.length),h&&u(A,A.keys[0],P),g(A,O),k(A,O)),A.values[0]}return Object.defineProperties(S,{cache:{configurable:!0,get:function(){return A}},cacheSnapshot:{configurable:!0,get:function(){return{keys:A.keys.slice(0),values:A.values.slice(0)}}},isMemoized:{configurable:!0,get:function(){return!0}},options:{configurable:!0,get:function(){return O}}}),S},Object.defineProperty(e,"__esModule",{value:!0})});
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?n(exports):"function"==typeof define&&define.amd?define(["exports"],n):n(e.memoize={})}(this,function(e){"use strict";var n=function(e){for(var n=new Array(e.length),r=0;r<e.length;r++)n[r]=e[r];return n},r=function(e){var n=function(e){return function(n,r){if(n.length!==r.length)return!1;for(var t=0;t<n.length;t++)if(!e(n[t],r[t]))return!1;return!0}}(e);return function(e,r){for(var t=0;t<e.length;t++)if(n(e[t],r))return t;return-1}},t=function(e){return function(n){var r=e(n);return Array.isArray(r)?r:[r]}},o=function(e,n){return e===n||e!=e&&n!=n},i=function(e,n){},u=function(e,n,r){for(var t=r;t--;)e[t+1]=e[t];e[0]=n},a=function(e,n,r){e.values[0]=e.values[0].catch(function(t){var o=r(e.keys,n);throw~o&&(e.keys.splice(o,1),e.values.splice(o,1)),t})};e.default=function(e,s){if(e.isMemoized)return e;var c=s||{},f=c.isEqual,l=void 0===f?o:f,v=c.isPromise,h=void 0!==v&&v,d=c.maxSize,y=void 0===d?1:d,g=c.onCacheAdd,p=void 0===g?i:g,m=c.onCacheChange,k=void 0===m?i:m,C=c.onCacheHit,b=void 0===C?i:C,x=c.transformKey,z=function(e,n){var r={};for(var t in e)n.indexOf(t)>=0||Object.prototype.hasOwnProperty.call(e,t)&&(r[t]=e[t]);return r}(c,["isEqual","isPromise","maxSize","onCacheAdd","onCacheChange","onCacheHit","transformKey"]),A=Object.assign({},z,{isEqual:l,isPromise:h,maxSize:y,onCacheAdd:p,onCacheChange:k,onCacheHit:b,transformKey:x}),O=r(l),P=x?t(x):null,j={keys:[],values:[]};function S(){var r=P?P(n(arguments)):arguments,t=O(j.keys,r);return~t?(b(j,A),t&&(u(j.keys,j.keys[t],t),u(j.values,j.values[t],t),k(j,A))):(j.keys.length>=y&&(j.keys.pop(),j.values.pop()),u(j.keys,P?r:n(r),j.keys.length),u(j.values,e.apply(this,arguments),j.values.length),h&&a(j,j.keys[0],O),p(j,A),k(j,A)),j.values[0]}return Object.defineProperties(S,{cache:{configurable:!0,get:function(){return j}},cacheSnapshot:{configurable:!0,get:function(){return{keys:n(j.keys),values:n(j.values)}}},isMemoized:{configurable:!0,get:function(){return!0}},options:{configurable:!0,get:function(){return A}}}),S},Object.defineProperty(e,"__esModule",{value:!0})});
function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; }
// utils
import { createGetKeyIndex, createGetTransformedKey, isSameValueZero, onCacheOperation, orderByLru, setPromiseCatch } from './utils';
import { cloneArray, createGetKeyIndex, createGetTransformedKey, isSameValueZero, onCacheOperation, orderByLru, setPromiseCatch } from './utils';
// types
var slice = [].slice;
/**

@@ -23,2 +18,5 @@ * @function memoize

*/
// types
export default function memoize(fn, options) {

@@ -73,3 +71,3 @@ // if it is a memoized method, don't re-memoize it

function memoized() {
var args = getTransformedKey ? getTransformedKey(slice.call(arguments, 0)) : arguments;
var args = getTransformedKey ? getTransformedKey(cloneArray(arguments)) : arguments;
var keyIndex = getKeyIndex(cache.keys, args);

@@ -92,3 +90,3 @@

orderByLru(cache.keys, getTransformedKey ? args : slice.call(args, 0), cache.keys.length);
orderByLru(cache.keys, getTransformedKey ? args : cloneArray(args), cache.keys.length);
orderByLru(cache.values, fn.apply(this, arguments), cache.values.length);

@@ -118,4 +116,4 @@

return {
keys: cache.keys.slice(0),
values: cache.values.slice(0)
keys: cloneArray(cache.keys),
values: cloneArray(cache.values)
};

@@ -122,0 +120,0 @@ }

/**
* @function cloneArray
*
* @description
* clone the array-like object and return the new array
*
* @param {Array<any>|Arguments} arrayLike the array-like object to clone
* @returns {Array<any>} the clone of the array
*/
export var cloneArray = function cloneArray(arrayLike) {
var array = new Array(arrayLike.length);
for (var index = 0; index < arrayLike.length; index++) {
array[index] = arrayLike[index];
}
return array;
};
// types
export var createAreKeysEqual = function createAreKeysEqual(isEqual) {

@@ -29,5 +51,2 @@ /**

// types
export var createGetKeyIndex = function createGetKeyIndex(isEqual) {

@@ -34,0 +53,0 @@ var areKeysEqual = createAreKeysEqual(isEqual);

@@ -13,5 +13,2 @@ 'use strict';

// types
var slice = [].slice;
/**

@@ -29,2 +26,5 @@ * @function memoize

*/
// types
function memoize(fn, options) {

@@ -79,3 +79,3 @@ // if it is a memoized method, don't re-memoize it

function memoized() {
var args = getTransformedKey ? getTransformedKey(slice.call(arguments, 0)) : arguments;
var args = getTransformedKey ? getTransformedKey((0, _utils.cloneArray)(arguments)) : arguments;
var keyIndex = getKeyIndex(cache.keys, args);

@@ -98,3 +98,3 @@

(0, _utils.orderByLru)(cache.keys, getTransformedKey ? args : slice.call(args, 0), cache.keys.length);
(0, _utils.orderByLru)(cache.keys, getTransformedKey ? args : (0, _utils.cloneArray)(args), cache.keys.length);
(0, _utils.orderByLru)(cache.values, fn.apply(this, arguments), cache.values.length);

@@ -124,4 +124,4 @@

return {
keys: cache.keys.slice(0),
values: cache.values.slice(0)
keys: (0, _utils.cloneArray)(cache.keys),
values: (0, _utils.cloneArray)(cache.values)
};

@@ -128,0 +128,0 @@ }

'use strict';
exports.__esModule = true;
/**
* @function cloneArray
*
* @description
* clone the array-like object and return the new array
*
* @param {Array<any>|Arguments} arrayLike the array-like object to clone
* @returns {Array<any>} the clone of the array
*/
var cloneArray = exports.cloneArray = function cloneArray(arrayLike) {
var array = new Array(arrayLike.length);
for (var index = 0; index < arrayLike.length; index++) {
array[index] = arrayLike[index];
}
return array;
};
// types
var createAreKeysEqual = exports.createAreKeysEqual = function createAreKeysEqual(isEqual) {

@@ -30,3 +52,2 @@ /**

// types
var createGetKeyIndex = exports.createGetKeyIndex = function createGetKeyIndex(isEqual) {

@@ -33,0 +54,0 @@ var areKeysEqual = createAreKeysEqual(isEqual);

@@ -122,3 +122,3 @@ {

"types": "./index.d.ts",
"version": "1.6.2"
"version": "1.6.3"
}

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