nano-memoize
Advanced tools
@@ -10,3 +10,3 @@ (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){ | ||
| nanomemoize = (fn, { | ||
| serializer = value => JSON.stringify(value), // used to serialize arguments of single argument functions, multis are not serialized | ||
| serializer, // used to serialize arguments of single argument functions, multis are not serialized | ||
| equals, // equality tester, will force use of slower multiarg approach even for single arg functions | ||
@@ -20,3 +20,6 @@ maxAge, // max cache age is ms, set higher than 0 if you want automatic clearing | ||
| v = [], // multiple arg function result cache | ||
| d = (key,m) => setTimeout(() => m ? delete v[key] : delete s[key],maxAge), | ||
| wm = {m:new WeakMap()}, | ||
| d = (key,c) => setTimeout(() => { | ||
| c instanceof WeakMap ? c.delete(key) : delete c[key] | ||
| },maxAge), | ||
| I = Infinity; | ||
@@ -29,11 +32,16 @@ let f, // memoized function to return | ||
| // s = result cache | ||
| // wm = weakmap | ||
| // c = cache change timeout | ||
| // p = arg serializer | ||
| // a = the arguments | ||
| f = (function(f,s,c,p,a) { // pre-bind core arguments, faster than using a closure or passing on stack | ||
| f = (function(f,s,wm,c,p,a) { // pre-bind core arguments, faster than using a closure or passing on stack | ||
| // strings must be serialized because cache[1] should not equal or overwrite cache["1"] for value = 1 and value = "1" | ||
| const t = typeof a, | ||
| key = !a || t === "number" || t === "boolean" ? a : p(a); | ||
| key = t === "number" || t === "boolean" || (!p && t === "object") ? a : t === "string" ? JSON.stringify(t) : p(a); | ||
| // set chng timeout only when new value computed, hits will not push out the tte, but it is arguable they should not | ||
| return s[key] || ((!c||c(key)),s[key] = fn.call(this, a)); | ||
| if(!p && t==="object") { | ||
| let r; | ||
| return wm.m.get(key) || ((!c||c(key,wm.m)),wm.m.set(key,r = fn.call(this, a)),r); | ||
| } | ||
| return s[key] || ((!c||c(key,s)),s[key] = fn.call(this, a)); | ||
| }).bind( | ||
@@ -43,3 +51,4 @@ this, | ||
| s, | ||
| maxAge && maxAge<I ? p => d(p) : 0, | ||
| wm, | ||
| maxAge && maxAge<I ? d : 0, | ||
| serializer | ||
@@ -73,3 +82,3 @@ ); | ||
| // set chng timeout only when new value computed, hits will not push out the tte, but it is arguable they should not | ||
| if(c) c(i); | ||
| if(c) c(i,v); | ||
| return v[i] = fn.apply(this,k[i] = a); | ||
@@ -82,3 +91,3 @@ }).bind( | ||
| equals, | ||
| maxAge && maxAge<I ? p => d(p,1) : 0, | ||
| maxAge && maxAge<I ? d : 0, | ||
| maxArgs | ||
@@ -90,2 +99,3 @@ ); | ||
| Object.keys(s).forEach(k => delete s[k]); | ||
| wm.m = new WeakMap(); | ||
| k.length = 0; | ||
@@ -96,3 +106,3 @@ v.length = 0; | ||
| f.values = _ => u ? null : v.slice(); | ||
| f.keyValues = _ => u ? Object.assign({},s) : null; | ||
| f.keyValues = _ => u ? {primitives:Object.assign({},s),objects:wm.m} : null; | ||
| return f; | ||
@@ -99,0 +109,0 @@ } |
@@ -1,1 +0,1 @@ | ||
| (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){(function(){"use strict";const vrgs=f=>{const s=f+"",i=s.indexOf("...");return i>=0&&i<s.indexOf(")"||s.indexOf("arguments")>=0)},nanomemoize=(fn,{serializer:serializer=(value=>JSON.stringify(value)),equals:equals,maxAge:maxAge,maxArgs:maxArgs,vargs:vargs=vrgs(fn)}={})=>{const s=Object.create(null),k=[],v=[],d=(key,m)=>setTimeout(()=>m?delete v[key]:delete s[key],maxAge),I=Infinity;let f,u;if(fn.length===1&&!equals&&!vargs){f=function(f,s,c,p,a){const t=typeof a,key=!a||t==="number"||t==="boolean"?a:p(a);return s[key]||(!c||c(key),s[key]=fn.call(this,a))}.bind(this,fn,s,maxAge&&maxAge<I?p=>d(p):0,serializer);u=1}else{f=function(f,k,v,e,c,m,...a){const l=m||a.length;let i;for(i=0;i<k.length;i++){let p=k[i];if(p&&p.length===a.length){for(let j=0;j<=l;j++){if(e?!e(p[j],a[j]):p[j]!==a[j])break;if(j===l){if(v[i]!==undefined)return v[i]}}}}if(c)c(i);return v[i]=fn.apply(this,k[i]=a)}.bind(this,fn,k,v,equals,maxAge&&maxAge<I?p=>d(p,1):0,maxArgs)}f.clear=(_=>{Object.keys(s).forEach(k=>delete s[k]);k.length=0;v.length=0});f.keys=(_=>u?null:k.slice());f.values=(_=>u?null:v.slice());f.keyValues=(_=>u?Object.assign({},s):null);return f};if(typeof module!=="undefined")module.exports=nanomemoize;if(typeof window!=="undefined")window.nanomemoize=nanomemoize}).call(this)},{}]},{},[1]); | ||
| (function e(t,n,r){function s(o,u){if(!n[o]){if(!t[o]){var a=typeof require=="function"&&require;if(!u&&a)return a(o,!0);if(i)return i(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=n[o]={exports:{}};t[o][0].call(l.exports,function(e){var n=t[o][1][e];return s(n?n:e)},l,l.exports,e,t,n,r)}return n[o].exports}var i=typeof require=="function"&&require;for(var o=0;o<r.length;o++)s(r[o]);return s})({1:[function(require,module,exports){(function(){"use strict";const vrgs=f=>{const s=f+"",i=s.indexOf("...");return i>=0&&i<s.indexOf(")"||s.indexOf("arguments")>=0)},nanomemoize=(fn,{serializer:serializer,equals:equals,maxAge:maxAge,maxArgs:maxArgs,vargs:vargs=vrgs(fn)}={})=>{const s=Object.create(null),k=[],v=[],wm={m:new WeakMap},d=(key,c)=>setTimeout(()=>{c instanceof WeakMap?c.delete(key):delete c[key]},maxAge),I=Infinity;let f,u;if(fn.length===1&&!equals&&!vargs){f=function(f,s,wm,c,p,a){const t=typeof a,key=t==="number"||t==="boolean"||!p&&t==="object"?a:t==="string"?JSON.stringify(t):p(a);if(!p&&t==="object"){let r;return wm.m.get(key)||(!c||c(key,wm.m),wm.m.set(key,r=fn.call(this,a)),r)}return s[key]||(!c||c(key,s),s[key]=fn.call(this,a))}.bind(this,fn,s,wm,maxAge&&maxAge<I?d:0,serializer);u=1}else{f=function(f,k,v,e,c,m,...a){const l=m||a.length;let i;for(i=0;i<k.length;i++){let p=k[i];if(p&&p.length===a.length){for(let j=0;j<=l;j++){if(e?!e(p[j],a[j]):p[j]!==a[j])break;if(j===l){if(v[i]!==undefined)return v[i]}}}}if(c)c(i,v);return v[i]=fn.apply(this,k[i]=a)}.bind(this,fn,k,v,equals,maxAge&&maxAge<I?d:0,maxArgs)}f.clear=(_=>{Object.keys(s).forEach(k=>delete s[k]);wm.m=new WeakMap;k.length=0;v.length=0});f.keys=(_=>u?null:k.slice());f.values=(_=>u?null:v.slice());f.keyValues=(_=>u?{primitives:Object.assign({},s),objects:wm.m}:null);return f};if(typeof module!=="undefined")module.exports=nanomemoize;if(typeof window!=="undefined")window.nanomemoize=nanomemoize}).call(this)},{}]},{},[1]); |
+19
-9
@@ -9,3 +9,3 @@ (function() { | ||
| nanomemoize = (fn, { | ||
| serializer = value => JSON.stringify(value), // used to serialize arguments of single argument functions, multis are not serialized | ||
| serializer, // used to serialize arguments of single argument functions, multis are not serialized | ||
| equals, // equality tester, will force use of slower multiarg approach even for single arg functions | ||
@@ -19,3 +19,6 @@ maxAge, // max cache age is ms, set higher than 0 if you want automatic clearing | ||
| v = [], // multiple arg function result cache | ||
| d = (key,m) => setTimeout(() => m ? delete v[key] : delete s[key],maxAge), | ||
| wm = {m:new WeakMap()}, | ||
| d = (key,c) => setTimeout(() => { | ||
| c instanceof WeakMap ? c.delete(key) : delete c[key] | ||
| },maxAge), | ||
| I = Infinity; | ||
@@ -28,11 +31,16 @@ let f, // memoized function to return | ||
| // s = result cache | ||
| // wm = weakmap | ||
| // c = cache change timeout | ||
| // p = arg serializer | ||
| // a = the arguments | ||
| f = (function(f,s,c,p,a) { // pre-bind core arguments, faster than using a closure or passing on stack | ||
| f = (function(f,s,wm,c,p,a) { // pre-bind core arguments, faster than using a closure or passing on stack | ||
| // strings must be serialized because cache[1] should not equal or overwrite cache["1"] for value = 1 and value = "1" | ||
| const t = typeof a, | ||
| key = !a || t === "number" || t === "boolean" ? a : p(a); | ||
| key = t === "number" || t === "boolean" || (!p && t === "object") ? a : t === "string" ? JSON.stringify(t) : p(a); | ||
| // set chng timeout only when new value computed, hits will not push out the tte, but it is arguable they should not | ||
| return s[key] || ((!c||c(key)),s[key] = fn.call(this, a)); | ||
| if(!p && t==="object") { | ||
| let r; | ||
| return wm.m.get(key) || ((!c||c(key,wm.m)),wm.m.set(key,r = fn.call(this, a)),r); | ||
| } | ||
| return s[key] || ((!c||c(key,s)),s[key] = fn.call(this, a)); | ||
| }).bind( | ||
@@ -42,3 +50,4 @@ this, | ||
| s, | ||
| maxAge && maxAge<I ? p => d(p) : 0, | ||
| wm, | ||
| maxAge && maxAge<I ? d : 0, | ||
| serializer | ||
@@ -72,3 +81,3 @@ ); | ||
| // set chng timeout only when new value computed, hits will not push out the tte, but it is arguable they should not | ||
| if(c) c(i); | ||
| if(c) c(i,v); | ||
| return v[i] = fn.apply(this,k[i] = a); | ||
@@ -81,3 +90,3 @@ }).bind( | ||
| equals, | ||
| maxAge && maxAge<I ? p => d(p,1) : 0, | ||
| maxAge && maxAge<I ? d : 0, | ||
| maxArgs | ||
@@ -89,2 +98,3 @@ ); | ||
| Object.keys(s).forEach(k => delete s[k]); | ||
| wm.m = new WeakMap(); | ||
| k.length = 0; | ||
@@ -95,3 +105,3 @@ v.length = 0; | ||
| f.values = _ => u ? null : v.slice(); | ||
| f.keyValues = _ => u ? Object.assign({},s) : null; | ||
| f.keyValues = _ => u ? {primitives:Object.assign({},s),objects:wm.m} : null; | ||
| return f; | ||
@@ -98,0 +108,0 @@ } |
@@ -1,1 +0,1 @@ | ||
| (function(){"use strict";const vrgs=f=>{const s=f+"",i=s.indexOf("...");return i>=0&&i<s.indexOf(")"||s.indexOf("arguments")>=0)},nanomemoize=(fn,{serializer:serializer=(value=>JSON.stringify(value)),equals:equals,maxAge:maxAge,maxArgs:maxArgs,vargs:vargs=vrgs(fn)}={})=>{const s=Object.create(null),k=[],v=[],d=(key,m)=>setTimeout(()=>m?delete v[key]:delete s[key],maxAge),I=Infinity;let f,u;if(fn.length===1&&!equals&&!vargs){f=function(f,s,c,p,a){const t=typeof a,key=!a||t==="number"||t==="boolean"?a:p(a);return s[key]||(!c||c(key),s[key]=fn.call(this,a))}.bind(this,fn,s,maxAge&&maxAge<I?p=>d(p):0,serializer);u=1}else{f=function(f,k,v,e,c,m,...a){const l=m||a.length;let i;for(i=0;i<k.length;i++){let p=k[i];if(p&&p.length===a.length){for(let j=0;j<=l;j++){if(e?!e(p[j],a[j]):p[j]!==a[j])break;if(j===l){if(v[i]!==undefined)return v[i]}}}}if(c)c(i);return v[i]=fn.apply(this,k[i]=a)}.bind(this,fn,k,v,equals,maxAge&&maxAge<I?p=>d(p,1):0,maxArgs)}f.clear=(_=>{Object.keys(s).forEach(k=>delete s[k]);k.length=0;v.length=0});f.keys=(_=>u?null:k.slice());f.values=(_=>u?null:v.slice());f.keyValues=(_=>u?Object.assign({},s):null);return f};if(typeof module!=="undefined")module.exports=nanomemoize;if(typeof window!=="undefined")window.nanomemoize=nanomemoize}).call(this); | ||
| (function(){"use strict";const vrgs=f=>{const s=f+"",i=s.indexOf("...");return i>=0&&i<s.indexOf(")"||s.indexOf("arguments")>=0)},nanomemoize=(fn,{serializer:serializer,equals:equals,maxAge:maxAge,maxArgs:maxArgs,vargs:vargs=vrgs(fn)}={})=>{const s=Object.create(null),k=[],v=[],wm={m:new WeakMap},d=(key,c)=>setTimeout(()=>{c instanceof WeakMap?c.delete(key):delete c[key]},maxAge),I=Infinity;let f,u;if(fn.length===1&&!equals&&!vargs){f=function(f,s,wm,c,p,a){const t=typeof a,key=t==="number"||t==="boolean"||!p&&t==="object"?a:t==="string"?JSON.stringify(t):p(a);if(!p&&t==="object"){let r;return wm.m.get(key)||(!c||c(key,wm.m),wm.m.set(key,r=fn.call(this,a)),r)}return s[key]||(!c||c(key,s),s[key]=fn.call(this,a))}.bind(this,fn,s,wm,maxAge&&maxAge<I?d:0,serializer);u=1}else{f=function(f,k,v,e,c,m,...a){const l=m||a.length;let i;for(i=0;i<k.length;i++){let p=k[i];if(p&&p.length===a.length){for(let j=0;j<=l;j++){if(e?!e(p[j],a[j]):p[j]!==a[j])break;if(j===l){if(v[i]!==undefined)return v[i]}}}}if(c)c(i,v);return v[i]=fn.apply(this,k[i]=a)}.bind(this,fn,k,v,equals,maxAge&&maxAge<I?d:0,maxArgs)}f.clear=(_=>{Object.keys(s).forEach(k=>delete s[k]);wm.m=new WeakMap;k.length=0;v.length=0});f.keys=(_=>u?null:k.slice());f.values=(_=>u?null:v.slice());f.keyValues=(_=>u?{primitives:Object.assign({},s),objects:wm.m}:null);return f};if(typeof module!=="undefined")module.exports=nanomemoize;if(typeof window!=="undefined")window.nanomemoize=nanomemoize}).call(this); |
+19
-9
@@ -9,3 +9,3 @@ (function() { | ||
| nanomemoize = (fn, { | ||
| serializer = value => JSON.stringify(value), // used to serialize arguments of single argument functions, multis are not serialized | ||
| serializer, // used to serialize arguments of single argument functions, multis are not serialized | ||
| equals, // equality tester, will force use of slower multiarg approach even for single arg functions | ||
@@ -19,3 +19,6 @@ maxAge, // max cache age is ms, set higher than 0 if you want automatic clearing | ||
| v = [], // multiple arg function result cache | ||
| d = (key,m) => setTimeout(() => m ? delete v[key] : delete s[key],maxAge), | ||
| wm = {m:new WeakMap()}, | ||
| d = (key,c) => setTimeout(() => { | ||
| c instanceof WeakMap ? c.delete(key) : delete c[key] | ||
| },maxAge), | ||
| I = Infinity; | ||
@@ -28,11 +31,16 @@ let f, // memoized function to return | ||
| // s = result cache | ||
| // wm = weakmap | ||
| // c = cache change timeout | ||
| // p = arg serializer | ||
| // a = the arguments | ||
| f = (function(f,s,c,p,a) { // pre-bind core arguments, faster than using a closure or passing on stack | ||
| f = (function(f,s,wm,c,p,a) { // pre-bind core arguments, faster than using a closure or passing on stack | ||
| // strings must be serialized because cache[1] should not equal or overwrite cache["1"] for value = 1 and value = "1" | ||
| const t = typeof a, | ||
| key = !a || t === "number" || t === "boolean" ? a : p(a); | ||
| key = t === "number" || t === "boolean" || (!p && t === "object") ? a : t === "string" ? JSON.stringify(t) : p(a); | ||
| // set chng timeout only when new value computed, hits will not push out the tte, but it is arguable they should not | ||
| return s[key] || ((!c||c(key)),s[key] = fn.call(this, a)); | ||
| if(!p && t==="object") { | ||
| let r; | ||
| return wm.m.get(key) || ((!c||c(key,wm.m)),wm.m.set(key,r = fn.call(this, a)),r); | ||
| } | ||
| return s[key] || ((!c||c(key,s)),s[key] = fn.call(this, a)); | ||
| }).bind( | ||
@@ -42,3 +50,4 @@ this, | ||
| s, | ||
| maxAge && maxAge<I ? p => d(p) : 0, | ||
| wm, | ||
| maxAge && maxAge<I ? d : 0, | ||
| serializer | ||
@@ -72,3 +81,3 @@ ); | ||
| // set chng timeout only when new value computed, hits will not push out the tte, but it is arguable they should not | ||
| if(c) c(i); | ||
| if(c) c(i,v); | ||
| return v[i] = fn.apply(this,k[i] = a); | ||
@@ -81,3 +90,3 @@ }).bind( | ||
| equals, | ||
| maxAge && maxAge<I ? p => d(p,1) : 0, | ||
| maxAge && maxAge<I ? d : 0, | ||
| maxArgs | ||
@@ -89,2 +98,3 @@ ); | ||
| Object.keys(s).forEach(k => delete s[k]); | ||
| wm.m = new WeakMap(); | ||
| k.length = 0; | ||
@@ -95,3 +105,3 @@ v.length = 0; | ||
| f.values = _ => u ? null : v.slice(); | ||
| f.keyValues = _ => u ? Object.assign({},s) : null; | ||
| f.keyValues = _ => u ? {primitives:Object.assign({},s),objects:wm.m} : null; | ||
| return f; | ||
@@ -98,0 +108,0 @@ } |
+1
-1
| { | ||
| "name": "nano-memoize", | ||
| "version": "v1.1.0", | ||
| "version": "v1.1.1", | ||
| "description": "Faster than fast, smaller than micro ... a nano speed and nano size memoizer.", | ||
@@ -5,0 +5,0 @@ "engines": {}, |
+4
-2
@@ -12,3 +12,3 @@ [](https://www.codacy.com/app/syblackwell/nano-memoize?utm_source=github.com&utm_medium=referral&utm_content=anywhichway/nano-memoize&utm_campaign=Badge_Grade) | ||
| The minified/brotli size is 623 Brotli bytes for `nano-memoize` v1.1.0 vs 2020 bytes for `micro-memoize` v3.0.1. And, `nano-memoize` has slightly more functionality. | ||
| The minified/brotli size is 640 Brotli bytes for `nano-memoize` v1.1.0 vs 2020 bytes for `micro-memoize` v3.0.1. And, `nano-memoize` has slightly more functionality. | ||
@@ -19,3 +19,3 @@ The speed tests are below. In most cases `nano-memoize` is the fastest. | ||
| * For single object argument functions`nano-memoize` is simply the fastest. | ||
| * For single primitive argument functions it is comparable to, but slightly and probably un-importantly faster that `fast-memoize`. | ||
@@ -208,2 +208,4 @@ * For multiple primitive argument functions`nano-memoize` is slightly and probably un-importantly faster than `micro-memoize`. | ||
| 2019-03-25 v1.1.1 Pushed incorrect version with v1.1.0. This corrects the version push. | ||
| 2019-03-25 v1.1.0 Added use of `WeakMap` for high-speed caching of single argument functions when passed objects. The `serializer` option no longer defaults to `(value) => JSON.stringify(value)` so if you want to treat objects that have the same string representation as the same, you will have to provide a `serializer`. | ||
@@ -210,0 +212,0 @@ |
+19
-9
@@ -9,3 +9,3 @@ (function() { | ||
| nanomemoize = (fn, { | ||
| serializer = value => JSON.stringify(value), // used to serialize arguments of single argument functions, multis are not serialized | ||
| serializer, // used to serialize arguments of single argument functions, multis are not serialized | ||
| equals, // equality tester, will force use of slower multiarg approach even for single arg functions | ||
@@ -19,3 +19,6 @@ maxAge, // max cache age is ms, set higher than 0 if you want automatic clearing | ||
| v = [], // multiple arg function result cache | ||
| d = (key,m) => setTimeout(() => m ? delete v[key] : delete s[key],maxAge), | ||
| wm = {m:new WeakMap()}, | ||
| d = (key,c) => setTimeout(() => { | ||
| c instanceof WeakMap ? c.delete(key) : delete c[key] | ||
| },maxAge), | ||
| I = Infinity; | ||
@@ -28,11 +31,16 @@ let f, // memoized function to return | ||
| // s = result cache | ||
| // wm = weakmap | ||
| // c = cache change timeout | ||
| // p = arg serializer | ||
| // a = the arguments | ||
| f = (function(f,s,c,p,a) { // pre-bind core arguments, faster than using a closure or passing on stack | ||
| f = (function(f,s,wm,c,p,a) { // pre-bind core arguments, faster than using a closure or passing on stack | ||
| // strings must be serialized because cache[1] should not equal or overwrite cache["1"] for value = 1 and value = "1" | ||
| const t = typeof a, | ||
| key = !a || t === "number" || t === "boolean" ? a : p(a); | ||
| key = t === "number" || t === "boolean" || (!p && t === "object") ? a : t === "string" ? JSON.stringify(t) : p(a); | ||
| // set chng timeout only when new value computed, hits will not push out the tte, but it is arguable they should not | ||
| return s[key] || ((!c||c(key)),s[key] = fn.call(this, a)); | ||
| if(!p && t==="object") { | ||
| let r; | ||
| return wm.m.get(key) || ((!c||c(key,wm.m)),wm.m.set(key,r = fn.call(this, a)),r); | ||
| } | ||
| return s[key] || ((!c||c(key,s)),s[key] = fn.call(this, a)); | ||
| }).bind( | ||
@@ -42,3 +50,4 @@ this, | ||
| s, | ||
| maxAge && maxAge<I ? p => d(p) : 0, | ||
| wm, | ||
| maxAge && maxAge<I ? d : 0, | ||
| serializer | ||
@@ -72,3 +81,3 @@ ); | ||
| // set chng timeout only when new value computed, hits will not push out the tte, but it is arguable they should not | ||
| if(c) c(i); | ||
| if(c) c(i,v); | ||
| return v[i] = fn.apply(this,k[i] = a); | ||
@@ -81,3 +90,3 @@ }).bind( | ||
| equals, | ||
| maxAge && maxAge<I ? p => d(p,1) : 0, | ||
| maxAge && maxAge<I ? d : 0, | ||
| maxArgs | ||
@@ -89,2 +98,3 @@ ); | ||
| Object.keys(s).forEach(k => delete s[k]); | ||
| wm.m = new WeakMap(); | ||
| k.length = 0; | ||
@@ -95,3 +105,3 @@ v.length = 0; | ||
| f.values = _ => u ? null : v.slice(); | ||
| f.keyValues = _ => u ? Object.assign({},s) : null; | ||
| f.keyValues = _ => u ? {primitives:Object.assign({},s),objects:wm.m} : null; | ||
| return f; | ||
@@ -98,0 +108,0 @@ } |
+16
-7
@@ -29,3 +29,3 @@ var chai, | ||
| result = singleArg(value), | ||
| keyvalues = singleArg.keyValues(); | ||
| keyvalues = singleArg.keyValues().primitives; | ||
| expect(result).to.equal(value); | ||
@@ -62,11 +62,21 @@ expect(keyvalues[value]).to.equal(value); | ||
| }); | ||
| it("expires content single",function(done) { | ||
| it("expires content single primitive",function(done) { | ||
| const expiring = nanomemoize((a) => a,{maxAge:5}); | ||
| expect(expiring(1)).to.equal(1); | ||
| expect(expiring.keyValues()[1]).to.equal(1); | ||
| expect(expiring.keyValues().primitives[1]).to.equal(1); | ||
| setTimeout(() => { | ||
| expect(expiring.keyValues()[1]).to.equal(undefined); | ||
| expect(expiring.keyValues().primitives[1]).to.equal(undefined); | ||
| done(); | ||
| },20) | ||
| }); | ||
| it("expires content single object",function(done) { | ||
| const expiring = nanomemoize((a) => a,{maxAge:5}), | ||
| o = {} | ||
| expect(expiring(o)).to.equal(o); | ||
| expect(expiring.keyValues().objects.get(o)).to.equal(o); | ||
| setTimeout(() => { | ||
| expect(expiring.keyValues().objects.get(o)).to.equal(undefined); | ||
| done(); | ||
| },20) | ||
| }); | ||
| it("expires content multiple",function(done) { | ||
@@ -87,8 +97,7 @@ const expiring = nanomemoize((a,b) => { return {a,b}; },{maxAge:5}), | ||
| expect(singleArg(value)).to.equal(value); | ||
| expect(singleArg.keyValues()[value]).to.equal(value); | ||
| expect(singleArg.keyValues().primitives[value]).to.equal(value); | ||
| singleArg.clear(); | ||
| expect(singleArg.keyValues()[value]).to.equal(undefined); | ||
| expect(singleArg.keyValues().primitives[value]).to.equal(undefined); | ||
| expect(singleArg(value)).to.equal(value); | ||
| expect(singleArg.keyValues()[value]).to.equal(value); | ||
| }); | ||
| }); |
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
Manifest confusion
Supply chain riskThis package has inconsistent metadata. This could be malicious or caused by an error when publishing the package.
Found 1 instance in 1 package
Minified code
QualityThis package contains minified code. This may be harmless in some cases where minified code is included in packaged libraries, however packages on npm should not minify code.
Found 1 instance in 1 package
57375
3.8%945
5.47%247
0.82%