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 3.0.1 to 3.0.2

38

__tests__/index.ts

@@ -18,2 +18,9 @@ // external dependencies

it('will throw an error if not a function', () => {
const fn = 123;
// @ts-ignore
expect(() => memoize(fn)).toThrow();
})
it('will return the memoized function', () => {

@@ -331,3 +338,3 @@ let callCount = 0;

const fn = async () => {
const fn = async (ignored: string) => {
await new Promise((resolve: Function) => {

@@ -367,6 +374,3 @@ setTimeout(resolve, timeout);

it('will fire the onCacheChange method passed with the cache when it is added to', () => {
const fn = (one: any, two: any) => ({
one,
two,
});
const fn = (one: string, two: string) => ({ one, two });
const onCacheChange = jest.fn();

@@ -378,3 +382,3 @@

memoized('foo');
memoized('foo', 'bar');

@@ -397,6 +401,3 @@ expect(onCacheChange).toHaveBeenCalledTimes(1);

it('will fire the onCacheChange method passed with the cache when it is updated', () => {
const fn = (one: any, two: any) => ({
one,
two,
});
const fn = (one: string, two: string) => ({ one, two });
const onCacheChange = jest.fn();

@@ -513,6 +514,3 @@ const maxSize = 2;

it('will not fire the onCacheHit method passed with the cache when it is added to', () => {
const fn = (one: any, two: any) => ({
one,
two,
});
const fn = (one: string, two: string) => ({ one, two });
const onCacheHit = jest.fn();

@@ -524,3 +522,3 @@

memoized('foo');
memoized('foo', 'bar');

@@ -656,7 +654,7 @@ expect(onCacheHit).toHaveBeenCalledTimes(0);

memoized('foo');
memoized('foo', 'bar');
expect(onCacheAdd).toHaveBeenCalledTimes(1);
memoized('foo');
memoized('foo', 'bar');

@@ -754,5 +752,9 @@ expect(onCacheAdd).toHaveBeenCalledTimes(1);

type Dictionary<Type> = {
[key: string]: Type;
}
test('if recursive calls to self will be respected at runtime', () => {
const calc = memoize(
(object: { [key: string]: any }, metadata: { c: number }): PlainObject =>
(object: { [key: string]: any }, metadata: { c: number }): Dictionary<any> =>
Object.keys(object).reduce((totals: { [key: string]: number }, key) => {

@@ -759,0 +761,0 @@ if (Array.isArray(object[key])) {

@@ -239,3 +239,3 @@ import {

const providedOptions = {
provided: 'options',
isPromise: true,
};

@@ -242,0 +242,0 @@

@@ -233,3 +233,3 @@ const _ = require('lodash');

...stats,
ops: stats.iterations / stats.elapsed,
ops: (stats.iterations / stats.elapsed) * 1000,
},

@@ -236,0 +236,0 @@ }))

# micro-memoize CHANGELOG
## 3.0.2
- Fix types declarations to ensure signature of `fn` passed is retained
- Throw an error when the first parameter passed is not a function
## 3.0.1

@@ -4,0 +9,0 @@

@@ -89,3 +89,2 @@ 'use strict';

if (!DEFAULT_OPTIONS_KEYS[key]) {
// @ts-ignore
customOptions[key] = options[key];

@@ -96,3 +95,18 @@ }

}
function isFunction(fn) {
return typeof fn === 'function';
}
/**
* @function isMemoized
*
* @description
* is the function passed already memoized
*
* @param fn the function to test
* @returns is the function already memoized
*/
function isMemoized(fn) {
return isFunction(fn) && fn.isMemoized;
}
/**
* @function isSameValueZero

@@ -190,10 +204,11 @@ *

// utils
var slice = Array.prototype.slice;
var defineProperties = Object.defineProperties;
var slice = Function.prototype.bind.call(Function.prototype.call, Array.prototype.slice);
function createMemoizedFunction(fn, options) {
if (options === void 0) { options = {}; }
// @ts-ignore
if (fn.isMemoized) {
if (isMemoized(fn)) {
return fn;
}
if (!isFunction(fn)) {
throw new TypeError('You must pass a function to `memoize`.');
}
var _a = options.isEqual, isEqual = _a === void 0 ? isSameValueZero : _a, isMatchingKey = options.isMatchingKey, _b = options.isPromise, isPromise = _b === void 0 ? false : _b, _c = options.maxSize, maxSize = _c === void 0 ? 1 : _c, onCacheAdd = options.onCacheAdd, onCacheChange = options.onCacheChange, onCacheHit = options.onCacheHit, transformKey = options.transformKey;

@@ -226,5 +241,6 @@ var normalizedOptions = mergeOptions(getCustomOptions(options), {

var shouldUpdateOnHit = typeof onCacheHit === 'function';
function memoized() {
// @ts-ignore
var memoized = function memoized() {
var normalizedArgs = shouldCloneArguments
? slice.call(arguments, 0)
? slice(arguments, 0)
: arguments;

@@ -243,3 +259,3 @@ var key = canTransformKey ? transformKey(normalizedArgs) : normalizedArgs;

var newValue = fn.apply(this, arguments);
var newKey = shouldCloneArguments ? key : slice.call(arguments, 0);
var newKey = shouldCloneArguments ? key : slice(arguments, 0);
orderByLru(cache, newKey, newValue, keys.length, maxSize);

@@ -251,4 +267,4 @@ isPromise && updateAsyncCache(cache, memoized);

return values[0];
}
defineProperties(memoized, {
};
Object.defineProperties(memoized, {
cache: {

@@ -262,5 +278,5 @@ configurable: true,

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

@@ -267,0 +283,0 @@ },

@@ -87,3 +87,2 @@ var DEFAULT_OPTIONS_KEYS = {

if (!DEFAULT_OPTIONS_KEYS[key]) {
// @ts-ignore
customOptions[key] = options[key];

@@ -94,3 +93,18 @@ }

}
function isFunction(fn) {
return typeof fn === 'function';
}
/**
* @function isMemoized
*
* @description
* is the function passed already memoized
*
* @param fn the function to test
* @returns is the function already memoized
*/
function isMemoized(fn) {
return isFunction(fn) && fn.isMemoized;
}
/**
* @function isSameValueZero

@@ -188,10 +202,11 @@ *

// utils
var slice = Array.prototype.slice;
var defineProperties = Object.defineProperties;
var slice = Function.prototype.bind.call(Function.prototype.call, Array.prototype.slice);
function createMemoizedFunction(fn, options) {
if (options === void 0) { options = {}; }
// @ts-ignore
if (fn.isMemoized) {
if (isMemoized(fn)) {
return fn;
}
if (!isFunction(fn)) {
throw new TypeError('You must pass a function to `memoize`.');
}
var _a = options.isEqual, isEqual = _a === void 0 ? isSameValueZero : _a, isMatchingKey = options.isMatchingKey, _b = options.isPromise, isPromise = _b === void 0 ? false : _b, _c = options.maxSize, maxSize = _c === void 0 ? 1 : _c, onCacheAdd = options.onCacheAdd, onCacheChange = options.onCacheChange, onCacheHit = options.onCacheHit, transformKey = options.transformKey;

@@ -224,5 +239,6 @@ var normalizedOptions = mergeOptions(getCustomOptions(options), {

var shouldUpdateOnHit = typeof onCacheHit === 'function';
function memoized() {
// @ts-ignore
var memoized = function memoized() {
var normalizedArgs = shouldCloneArguments
? slice.call(arguments, 0)
? slice(arguments, 0)
: arguments;

@@ -241,3 +257,3 @@ var key = canTransformKey ? transformKey(normalizedArgs) : normalizedArgs;

var newValue = fn.apply(this, arguments);
var newKey = shouldCloneArguments ? key : slice.call(arguments, 0);
var newKey = shouldCloneArguments ? key : slice(arguments, 0);
orderByLru(cache, newKey, newValue, keys.length, maxSize);

@@ -249,4 +265,4 @@ isPromise && updateAsyncCache(cache, memoized);

return values[0];
}
defineProperties(memoized, {
};
Object.defineProperties(memoized, {
cache: {

@@ -260,5 +276,5 @@ configurable: true,

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

@@ -265,0 +281,0 @@ },

@@ -93,3 +93,2 @@ (function (global, factory) {

if (!DEFAULT_OPTIONS_KEYS[key]) {
// @ts-ignore
customOptions[key] = options[key];

@@ -100,3 +99,18 @@ }

}
function isFunction(fn) {
return typeof fn === 'function';
}
/**
* @function isMemoized
*
* @description
* is the function passed already memoized
*
* @param fn the function to test
* @returns is the function already memoized
*/
function isMemoized(fn) {
return isFunction(fn) && fn.isMemoized;
}
/**
* @function isSameValueZero

@@ -194,10 +208,11 @@ *

// utils
var slice = Array.prototype.slice;
var defineProperties = Object.defineProperties;
var slice = Function.prototype.bind.call(Function.prototype.call, Array.prototype.slice);
function createMemoizedFunction(fn, options) {
if (options === void 0) { options = {}; }
// @ts-ignore
if (fn.isMemoized) {
if (isMemoized(fn)) {
return fn;
}
if (!isFunction(fn)) {
throw new TypeError('You must pass a function to `memoize`.');
}
var _a = options.isEqual, isEqual = _a === void 0 ? isSameValueZero : _a, isMatchingKey = options.isMatchingKey, _b = options.isPromise, isPromise = _b === void 0 ? false : _b, _c = options.maxSize, maxSize = _c === void 0 ? 1 : _c, onCacheAdd = options.onCacheAdd, onCacheChange = options.onCacheChange, onCacheHit = options.onCacheHit, transformKey = options.transformKey;

@@ -230,5 +245,6 @@ var normalizedOptions = mergeOptions(getCustomOptions(options), {

var shouldUpdateOnHit = typeof onCacheHit === 'function';
function memoized() {
// @ts-ignore
var memoized = function memoized() {
var normalizedArgs = shouldCloneArguments
? slice.call(arguments, 0)
? slice(arguments, 0)
: arguments;

@@ -247,3 +263,3 @@ var key = canTransformKey ? transformKey(normalizedArgs) : normalizedArgs;

var newValue = fn.apply(this, arguments);
var newKey = shouldCloneArguments ? key : slice.call(arguments, 0);
var newKey = shouldCloneArguments ? key : slice(arguments, 0);
orderByLru(cache, newKey, newValue, keys.length, maxSize);

@@ -255,4 +271,4 @@ isPromise && updateAsyncCache(cache, memoized);

return values[0];
}
defineProperties(memoized, {
};
Object.defineProperties(memoized, {
cache: {

@@ -266,5 +282,5 @@ configurable: true,

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

@@ -271,0 +287,0 @@ },

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

!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e=e||self)["micro-memoize"]=n()}(this,function(){"use strict";var P={isEqual:!0,isMatchingKey:!0,isPromise:!0,maxSize:!0,onCacheAdd:!0,onCacheChange:!0,onCacheHit:!0,transformKey:!0};function j(e){var u=e.isEqual,r=e.isMatchingKey,o=e.maxSize;return"function"==typeof r?function(e,n){if(r(e[0],n))return 0;if(1<o)for(var t=e.length,i=1;i<t;i++)if(r(e[i],n))return i;return-1}:1<o?function(e,n){for(var t,i=e.length,r=n.length,o=0;o<i;o++)if((t=e[o]).length===r){for(var a=0;a<r&&u(t[a],n[a]);a++);if(a===r)return o}return-1}:function(e,n){var t=e[0],i=t.length;if(n.length!==i)return-1;for(var r=0;r<i;r++)if(!u(t[r],n[r]))return-1;return 0}}function w(e,n){return e===n||e!=e&&n!=n}function O(e,n,t,i,r){for(var o=i;o--;)e.keys[o+1]=e.keys[o],e.values[o+1]=e.values[o];e.keys[0]=n,e.values[0]=t,r<=i&&(e.keys.length=r,e.values.length=r)}var B=Array.prototype.slice,D=Object.defineProperties;return function(o,e){if(void 0===e&&(e={}),o.isMemoized)return o;var r,a,u,f,c,s,n=e.isEqual,t=void 0===n?w:n,i=e.isMatchingKey,l=e.isPromise,h=void 0!==l&&l,v=e.maxSize,y=void 0===v?1:v,g=e.onCacheAdd,d=e.onCacheChange,p=e.onCacheHit,m=e.transformKey,C=function(e,n){var t={};for(var i in e)t[i]=e[i];for(var i in n)t[i]=n[i];return t}(function(e){var n={};for(var t in e)P[t]||(n[t]=e[t]);return n}(e),{isEqual:t,isMatchingKey:i,isPromise:h,maxSize:y,onCacheAdd:g,onCacheChange:d,onCacheHit:p,transformKey:m}),k=j(C),z=(a=j(r=C),u=r.onCacheChange,f=r.onCacheHit,c="function"==typeof u,s="function"==typeof f,function(t,n){var i=t.keys[0];t.values[0]=t.values[0].then(function(e){return s&&f(t,r,n),c&&u(t,r,n),e}).catch(function(e){var n=a(t.keys,i);throw-1!==n&&(t.keys.splice(n,1),t.values.splice(n,1)),e})}),K=[],b=[],x={keys:K,get size(){return x.keys.length},values:b},M="function"==typeof m,S=!(!m&&!i),q="function"==typeof g,A="function"==typeof d,E="function"==typeof p;function H(){var e=S?B.call(arguments,0):arguments,n=M?m(e):e,t=K.length?k(K,n):-1;if(-1!==t)E&&p(x,C,H),t&&(O(x,K[t],b[t],t,y),A&&d(x,C,H));else{var i=o.apply(this,arguments),r=S?n:B.call(arguments,0);O(x,r,i,K.length,y),h&&z(x,H),q&&g(x,C,H),A&&d(x,C,H)}return b[0]}return D(H,{cache:{configurable:!0,value:x},cacheSnapshot:{configurable:!0,get:function(){return{keys:B.call(x.keys,0),size:x.size,values:B.call(x.values,0)}}},isMemoized:{configurable:!0,value:!0},options:{configurable:!0,value:C}}),H}});
!function(e,n){"object"==typeof exports&&"undefined"!=typeof module?module.exports=n():"function"==typeof define&&define.amd?define(n):(e=e||self)["micro-memoize"]=n()}(this,function(){"use strict";var M={isEqual:!0,isMatchingKey:!0,isPromise:!0,maxSize:!0,onCacheAdd:!0,onCacheChange:!0,onCacheHit:!0,transformKey:!0};function E(e){var a=e.isEqual,r=e.isMatchingKey,o=e.maxSize;return"function"==typeof r?function(e,n){if(r(e[0],n))return 0;if(1<o)for(var t=e.length,i=1;i<t;i++)if(r(e[i],n))return i;return-1}:1<o?function(e,n){for(var t,i=e.length,r=n.length,o=0;o<i;o++)if((t=e[o]).length===r){for(var u=0;u<r&&a(t[u],n[u]);u++);if(u===r)return o}return-1}:function(e,n){var t=e[0],i=t.length;if(n.length!==i)return-1;for(var r=0;r<i;r++)if(!a(t[r],n[r]))return-1;return 0}}function S(e){return"function"==typeof e}function q(e,n){return e===n||e!=e&&n!=n}function A(e,n,t,i,r){for(var o=i;o--;)e.keys[o+1]=e.keys[o],e.values[o+1]=e.values[o];e.keys[0]=n,e.values[0]=t,r<=i&&(e.keys.length=r,e.values.length=r)}var H=Function.prototype.bind.call(Function.prototype.call,Array.prototype.slice);return function(o,e){if(void 0===e&&(e={}),function(e){return S(e)&&e.isMemoized}(o))return o;if(!S(o))throw new TypeError("You must pass a function to `memoize`.");function u(){var e=z?H(arguments,0):arguments,n=k?v(e):e,t=d.length?p(d,n):-1;if(-1!==t)x&&h(C,y,u),t&&(A(C,d[t],m[t],t,c),K&&l(C,y,u));else{var i=o.apply(this,arguments),r=z?n:H(arguments,0);A(C,r,i,d.length,c),a&&g(C,u),b&&s(C,y,u),K&&l(C,y,u)}return m[0]}var n=e.isEqual,t=void 0===n?q:n,i=e.isMatchingKey,r=e.isPromise,a=void 0!==r&&r,f=e.maxSize,c=void 0===f?1:f,s=e.onCacheAdd,l=e.onCacheChange,h=e.onCacheHit,v=e.transformKey,y=function(e,n){var t={};for(var i in e)t[i]=e[i];for(var i in n)t[i]=n[i];return t}(function(e){var n={};for(var t in e)M[t]||(n[t]=e[t]);return n}(e),{isEqual:t,isMatchingKey:i,isPromise:a,maxSize:c,onCacheAdd:s,onCacheChange:l,onCacheHit:h,transformKey:v}),p=E(y),g=function(r){var o=E(r),u=r.onCacheChange,a=r.onCacheHit,f="function"==typeof u,c="function"==typeof a;return function(t,n){var i=t.keys[0];t.values[0]=t.values[0].then(function(e){return c&&a(t,r,n),f&&u(t,r,n),e}).catch(function(e){var n=o(t.keys,i);throw-1!==n&&(t.keys.splice(n,1),t.values.splice(n,1)),e})}}(y),d=[],m=[],C={keys:d,get size(){return C.keys.length},values:m},k="function"==typeof v,z=!(!v&&!i),b="function"==typeof s,K="function"==typeof l,x="function"==typeof h;return Object.defineProperties(u,{cache:{configurable:!0,value:C},cacheSnapshot:{configurable:!0,get:function(){return{keys:H(C.keys,0),size:C.size,values:H(C.values,0)}}},isMemoized:{configurable:!0,value:!0},options:{configurable:!0,value:y}}),u}});

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

type Dictionary<Type> = {
[key: string]: Type;
[index: number]: Type;
};
declare namespace MicroMemoize {

@@ -22,3 +27,3 @@ export type Key = any[];

cache: Cache,
options: Options,
options: StandardOptions,
memoized: Function,

@@ -31,7 +36,8 @@ ) => void;

export type AsyncCacheUpdater = (cache: Cache, memoized: Memoized) => void;
export type AsyncCacheUpdater = (
cache: Cache,
memoized: Memoized<Function>,
) => void;
export type Options = {
[key: string]: any;
[index: number]: any;
export type StandardOptions = {
isEqual?: EqualityComparator;

@@ -47,3 +53,5 @@ isMatchingKey?: MatchingKeyComparator;

export interface Memoized extends Function {
export type Options = StandardOptions & Dictionary<any>;
export type Memoized<Fn extends Function> = Fn & {
[key: string]: any;

@@ -54,8 +62,3 @@ cache?: Cache;

options?: Options;
}
};
}
export default function memoize<T extends Function>(
fn: T | MicroMemoize.Memoized,
options?: MicroMemoize.Options,
): MicroMemoize.Memoized;

@@ -17,39 +17,39 @@ {

"devDependencies": {
"@types/bluebird": "^3.5.25",
"@types/jest": "^24.0.5",
"@types/react": "^16.8.3",
"benchee": "^1.0.0",
"@types/bluebird": "^3.5.27",
"@types/jest": "^24.0.13",
"@types/react": "^16.8.18",
"benchee": "^1.1.0",
"benchmark": "^2.1.4",
"bluebird": "^3.5.2",
"bluebird": "^3.5.5",
"cli-table2": "^0.2.0",
"fast-equals": "^1.6.1",
"fast-equals": "^2.0.0",
"fast-memoize": "^2.5.1",
"html-webpack-plugin": "^3.2.0",
"in-publish": "^2.0.0",
"jest": "^24.1.0",
"jest": "^24.8.0",
"lodash": "^4.17.11",
"lru-memoize": "^1.0.2",
"mem": "^4.0.0",
"lru-memoize": "^1.1.0",
"mem": "^5.0.0",
"memoizee": "^0.4.14",
"memoizerific": "^1.11.3",
"mini-bench": "^1.0.0",
"ora": "^3.1.0",
"ora": "^3.4.0",
"performance-now": "^2.1.0",
"ramda": "^0.26.1",
"react": "^16.8.2",
"rollup": "^1.1.2",
"rollup-plugin-typescript": "^1.0.0",
"react": "^16.8.6",
"rollup": "^1.12.4",
"rollup-plugin-typescript": "^1.0.1",
"rollup-plugin-uglify": "^6.0.0",
"rsvp": "^4.8.4",
"simple-statistics": "^7.0.0",
"ts-jest": "^23.10.4",
"ts-loader": "^5.2.2",
"tslint": "^5.11.0",
"simple-statistics": "^7.0.2",
"ts-jest": "^24.0.2",
"ts-loader": "^6.0.1",
"tslint": "^5.16.0",
"tslint-config-airbnb": "^5.11.0",
"tslint-loader": "^3.5.4",
"typescript": "^3.1.3",
"typescript": "^3.4.5",
"underscore": "^1.9.1",
"webpack": "^4.29.4",
"webpack-cli": "^3.1.2",
"webpack-dev-server": "^3.1.9"
"webpack": "^4.32.2",
"webpack-cli": "^3.3.2",
"webpack-dev-server": "^3.4.1"
},

@@ -101,3 +101,3 @@ "homepage": "https://github.com/planttheidea/micro-memoize#readme",

"types": "./index.d.ts",
"version": "3.0.1"
"version": "3.0.2"
}

@@ -35,3 +35,3 @@ # micro-memoize

As the author of [`moize`](https://github.com/planttheidea/moize), I created a consistently fast memoization library, but `moize` has a lot of features to satisfy a large number of edge cases. `micro-memoize` is a simpler approach, focusing on the core feature set with a much smaller footprint (~1.2kB minified+gzipped). Stripping out these edge cases also allows `micro-memoize` to be faster across the board than `moize`.
As the author of [`moize`](https://github.com/planttheidea/moize), I created a consistently fast memoization library, but `moize` has a lot of features to satisfy a large number of edge cases. `micro-memoize` is a simpler approach, focusing on the core feature set with a much smaller footprint (~1.3kB minified+gzipped). Stripping out these edge cases also allows `micro-memoize` to be faster across the board than `moize`.

@@ -43,3 +43,3 @@ ## Importing

```javascript
import memoize from 'micro-memoize';
import memoize from "micro-memoize";
```

@@ -50,3 +50,3 @@

```javascript
import memoize from 'micro-memoize/mjs';
import memoize from "micro-memoize/mjs";
```

@@ -57,3 +57,3 @@

```javascript
const memoize = require('micro-memoize');
const memoize = require("micro-memoize");
```

@@ -70,4 +70,4 @@

console.log(memoized('one', 'two')); // {one: 'one', two: 'two'}
console.log(memoized('one', 'two')); // pulled from cache, {one: 'one', two: 'two'}
console.log(memoized("one", "two")); // {one: 'one', two: 'two'}
console.log(memoized("one", "two")); // pulled from cache, {one: 'one', two: 'two'}
```

@@ -89,3 +89,3 @@

```javascript
import { deepEqual } from 'fast-equals';
import { deepEqual } from "fast-equals";

@@ -95,3 +95,3 @@ const deepObject = object => {

foo: object.foo,
bar: object.bar,
bar: object.bar
};

@@ -105,11 +105,11 @@ };

foo: {
deep: 'foo',
deep: "foo"
},
bar: {
deep: 'bar',
deep: "bar"
},
baz: {
deep: 'baz',
},
}),
deep: "baz"
}
})
); // {foo: {deep: 'foo'}, bar: {deep: 'bar'}}

@@ -120,11 +120,11 @@

foo: {
deep: 'foo',
deep: "foo"
},
bar: {
deep: 'bar',
deep: "bar"
},
baz: {
deep: 'baz',
},
}),
deep: "baz"
}
})
); // pulled from cache

@@ -148,3 +148,3 @@ ```

```javascript
import { deepEqual } from 'fast-equals';
import { deepEqual } from "fast-equals";

@@ -154,3 +154,3 @@ const deepObject = object => {

foo: object.foo,
bar: object.bar,
bar: object.bar
};

@@ -162,7 +162,7 @@ };

return (
object1.hasOwnProperty('foo') &&
object2.hasOwnProperty('foo') &&
object1.hasOwnProperty("foo") &&
object2.hasOwnProperty("foo") &&
object1.bar === object2.bar
);
},
}
});

@@ -172,6 +172,6 @@

memoizedShape({
foo: 'foo',
bar: 'bar',
baz: 'baz',
}),
foo: "foo",
bar: "bar",
baz: "baz"
})
); // {foo: {deep: 'foo'}, bar: {deep: 'bar'}}

@@ -181,6 +181,6 @@

memoizedShape({
foo: 'not foo',
bar: 'bar',
baz: 'baz',
}),
foo: "not foo",
bar: "bar",
baz: "baz"
})
); // pulled from cache

@@ -209,3 +209,3 @@ ```

memoized('one', 'two');
memoized("one", "two");

@@ -236,11 +236,11 @@ console.log(memoized.cacheSnapshot.keys); // [['one', 'two']]

console.log(memoized('one', 'two')); // ['one', 'two']
console.log(memoized('two', 'three')); // ['two', 'three']
console.log(memoized('three', 'four')); // ['three', 'four']
console.log(memoized("one", "two")); // ['one', 'two']
console.log(memoized("two", "three")); // ['two', 'three']
console.log(memoized("three", "four")); // ['three', 'four']
console.log(memoized('one', 'two')); // pulled from cache
console.log(memoized('two', 'three')); // pulled from cache
console.log(memoized('three', 'four')); // pulled from cache
console.log(memoized("one", "two")); // pulled from cache
console.log(memoized("two", "three")); // pulled from cache
console.log(memoized("three", "four")); // pulled from cache
console.log(memoized('four', 'five')); // ['four', 'five'], drops ['one', 'two'] from cache
console.log(memoized("four", "five")); // ['four', 'five'], drops ['one', 'two'] from cache
```

@@ -263,18 +263,18 @@

onCacheAdd(cache, options) {
console.log('cache has been added to: ', cache);
console.log('memoized method has the following options applied: ', options);
},
console.log("cache has been added to: ", cache);
console.log("memoized method has the following options applied: ", options);
}
});
memoized('foo', 'bar'); // cache has been added to
memoized('foo', 'bar');
memoized('foo', 'bar');
memoized("foo", "bar"); // cache has been added to
memoized("foo", "bar");
memoized("foo", "bar");
memoized('bar', 'foo'); // cache has been added to
memoized('bar', 'foo');
memoized('bar', 'foo');
memoized("bar", "foo"); // cache has been added to
memoized("bar", "foo");
memoized("bar", "foo");
memoized('foo', 'bar');
memoized('foo', 'bar');
memoized('foo', 'bar');
memoized("foo", "bar");
memoized("foo", "bar");
memoized("foo", "bar");
```

@@ -297,18 +297,18 @@

onCacheChange(cache, options) {
console.log('cache has changed: ', cache);
console.log('memoized method has the following options applied: ', options);
},
console.log("cache has changed: ", cache);
console.log("memoized method has the following options applied: ", options);
}
});
memoized('foo', 'bar'); // cache has changed
memoized('foo', 'bar');
memoized('foo', 'bar');
memoized("foo", "bar"); // cache has changed
memoized("foo", "bar");
memoized("foo", "bar");
memoized('bar', 'foo'); // cache has changed
memoized('bar', 'foo');
memoized('bar', 'foo');
memoized("bar", "foo"); // cache has changed
memoized("bar", "foo");
memoized("bar", "foo");
memoized('foo', 'bar'); // cache has changed
memoized('foo', 'bar');
memoized('foo', 'bar');
memoized("foo", "bar"); // cache has changed
memoized("foo", "bar");
memoized("foo", "bar");
```

@@ -332,18 +332,18 @@

onCacheHit(cache, options) {
console.log('cache was hit: ', cache);
console.log('memoized method has the following options applied: ', options);
},
console.log("cache was hit: ", cache);
console.log("memoized method has the following options applied: ", options);
}
});
memoized('foo', 'bar');
memoized('foo', 'bar'); // cache was hit
memoized('foo', 'bar'); // cache was hit
memoized("foo", "bar");
memoized("foo", "bar"); // cache was hit
memoized("foo", "bar"); // cache was hit
memoized('bar', 'foo');
memoized('bar', 'foo'); // cache was hit
memoized('bar', 'foo'); // cache was hit
memoized("bar", "foo");
memoized("bar", "foo"); // cache was hit
memoized("bar", "foo"); // cache was hit
memoized('foo', 'bar'); // cache was hit
memoized('foo', 'bar'); // cache was hit
memoized('foo', 'bar'); // cache was hit
memoized("foo", "bar"); // cache was hit
memoized("foo", "bar"); // cache was hit
memoized("foo", "bar"); // cache was hit
```

@@ -365,7 +365,7 @@

const memoized = memoize(ignoreFunctionArgs, {
transformKey: JSON.stringify,
transformKey: JSON.stringify
});
console.log(memoized('one', () => {})); // ['one', () => {}]
console.log(memoized('one', () => {})); // pulled from cache, ['one', () => {}]
console.log(memoized("one", () => {})); // ['one', () => {}]
console.log(memoized("one", () => {})); // pulled from cache, ['one', () => {}]
```

@@ -386,9 +386,9 @@

return {
args: JSON.stringify(args),
args: JSON.stringify(args)
};
},
}
});
console.log(memoized('one', () => {})); // ['one', () => {}]
console.log(memoized('one', () => {})); // pulled from cache, ['one', () => {}]
console.log(memoized("one", () => {})); // ['one', () => {}]
console.log(memoized("one", () => {})); // pulled from cache, ['one', () => {}]
```

@@ -420,6 +420,6 @@

memoized.cache.keys.push(['one', 'two']);
memoized.cache.values.push('cached');
memoized.cache.keys.push(["one", "two"]);
memoized.cache.values.push("cached");
console.log(memoized('one', 'two')); // 'cached'
console.log(memoized("one", "two")); // 'cached'
```

@@ -426,0 +426,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

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