nano-memoize
Advanced tools
Comparing version 1.1.11 to 1.2.0
@@ -78,2 +78,3 @@ (function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){ | ||
for(i=k.length-1;i>=0;i--) { // an array of arrays of args, each array represents a call signature | ||
if (!maxargs && k[i].length !== l) continue; // cache miss if called with a different number of args | ||
for(var j=l-1;j>=0 && eq(k[i][j],arguments[j]);j--) { // compare each arg | ||
@@ -80,0 +81,0 @@ if(j===0) { return v[i]; } // the args matched |
@@ -1,1 +0,1 @@ | ||
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){(function(){"use strict";var assign=Object.assign;if(typeof assign!=="function"){assign=function(){var a=arguments,o=arguments[0];if(o===null||o===undefined){throw new TypeError("Cannot convert undefined or null to object")}o=Object(o);for(var i=1;i<a.length;i++){if(a[i]&&typeof a[i]==="object"){for(var k in a[i]){o[k]=a[i][k]}}}return o}}function vrgs(f){var s=f+"",i=s.indexOf("...");return i>=0&&(i<s.indexOf(")")||s.indexOf("arguments")>=0)}function nanomemoize(fn,o){o||(o={});var vargs=o.vargs||vrgs(fn),s=Object.create(null),k=[],v=[],wm=new WeakMap,d=function(key,c,k){return setTimeout(function(){if(k){c.splice(key,1);k.splice(key,1);return}c instanceof WeakMap?c.delete(key):delete c[key]},o.maxAge)},c=o.maxAge>0&&o.maxAge<Infinity?d:0,eq=o.equals?o.equals:function(a,b){return a===b},maxargs=o.maxArgs,srlz=o.serializer,f,u;if(fn.length===1&&!o.equals&&!vargs){f=function(a){var t=typeof a;if(!srlz&&(t==="object"&&a||t==="function")){var r;return wm.get(a)||(!c||c(a,wm),wm.set(a,r=fn.call(this,a)),r)}var key=t==="number"||t==="boolean"||a==null?a:t==="string"?JSON.stringify(a):srlz(a);return s[key]||(!c||c(key,s),s[key]=fn.call(this,a))}.bind(this);u=1}else{f=function(){var l=maxargs||arguments.length,i;for(i=k.length-1;i>=0;i--){for(var j=l-1;j>=0&&eq(k[i][j],arguments[j]);j--){if(j===0){return v[i]}}}i=k.length-(i+1);return!c||c(i,v,k),v[i]=fn.apply(this,k[i]=arguments)}.bind(this)}f.clear=function(){wm=new WeakMap;s=Object.create(null);k=[];v=[]};f.keys=function(){return u?null:k.slice()};f.values=function(){return u?null:v.slice()};f.keyValues=function(){return u?{primitives:assign({},s),objects:wm}:null};return f}if(typeof module!=="undefined"){module.exports=nanomemoize}if(typeof window!=="undefined"){window.nanomemoize=nanomemoize}}).call(this)},{}]},{},[1]); | ||
(function(){function r(e,n,t){function o(i,f){if(!n[i]){if(!e[i]){var c="function"==typeof require&&require;if(!f&&c)return c(i,!0);if(u)return u(i,!0);var a=new Error("Cannot find module '"+i+"'");throw a.code="MODULE_NOT_FOUND",a}var p=n[i]={exports:{}};e[i][0].call(p.exports,function(r){var n=e[i][1][r];return o(n||r)},p,p.exports,r,e,n,t)}return n[i].exports}for(var u="function"==typeof require&&require,i=0;i<t.length;i++)o(t[i]);return o}return r})()({1:[function(require,module,exports){(function(){"use strict";var assign=Object.assign;if(typeof assign!=="function"){assign=function(){var a=arguments,o=arguments[0];if(o===null||o===undefined){throw new TypeError("Cannot convert undefined or null to object")}o=Object(o);for(var i=1;i<a.length;i++){if(a[i]&&typeof a[i]==="object"){for(var k in a[i]){o[k]=a[i][k]}}}return o}}function vrgs(f){var s=f+"",i=s.indexOf("...");return i>=0&&(i<s.indexOf(")")||s.indexOf("arguments")>=0)}function nanomemoize(fn,o){o||(o={});var vargs=o.vargs||vrgs(fn),s=Object.create(null),k=[],v=[],wm=new WeakMap,d=function(key,c,k){return setTimeout(function(){if(k){c.splice(key,1);k.splice(key,1);return}c instanceof WeakMap?c.delete(key):delete c[key]},o.maxAge)},c=o.maxAge>0&&o.maxAge<Infinity?d:0,eq=o.equals?o.equals:function(a,b){return a===b},maxargs=o.maxArgs,srlz=o.serializer,f,u;if(fn.length===1&&!o.equals&&!vargs){f=function(a){var t=typeof a;if(!srlz&&(t==="object"&&a||t==="function")){var r;return wm.get(a)||(!c||c(a,wm),wm.set(a,r=fn.call(this,a)),r)}var key=t==="number"||t==="boolean"||a==null?a:t==="string"?JSON.stringify(a):srlz(a);return s[key]||(!c||c(key,s),s[key]=fn.call(this,a))}.bind(this);u=1}else{f=function(){var l=maxargs||arguments.length,i;for(i=k.length-1;i>=0;i--){if(!maxargs&&k[i].length!==l)continue;for(var j=l-1;j>=0&&eq(k[i][j],arguments[j]);j--){if(j===0){return v[i]}}}i=k.length-(i+1);return!c||c(i,v,k),v[i]=fn.apply(this,k[i]=arguments)}.bind(this)}f.clear=function(){wm=new WeakMap;s=Object.create(null);k=[];v=[]};f.keys=function(){return u?null:k.slice()};f.values=function(){return u?null:v.slice()};f.keyValues=function(){return u?{primitives:assign({},s),objects:wm}:null};return f}if(typeof module!=="undefined"){module.exports=nanomemoize}if(typeof window!=="undefined"){window.nanomemoize=nanomemoize}}).call(this)},{}]},{},[1]); |
@@ -77,2 +77,3 @@ (function() { | ||
for(i=k.length-1;i>=0;i--) { // an array of arrays of args, each array represents a call signature | ||
if (!maxargs && k[i].length !== l) continue; // cache miss if called with a different number of args | ||
for(var j=l-1;j>=0 && eq(k[i][j],arguments[j]);j--) { // compare each arg | ||
@@ -79,0 +80,0 @@ if(j===0) { return v[i]; } // the args matched |
@@ -1,1 +0,1 @@ | ||
(function(){"use strict";var assign=Object.assign;if(typeof assign!=="function"){assign=function(){var a=arguments,o=arguments[0];if(o===null||o===undefined){throw new TypeError("Cannot convert undefined or null to object")}o=Object(o);for(var i=1;i<a.length;i++){if(a[i]&&typeof a[i]==="object"){for(var k in a[i]){o[k]=a[i][k]}}}return o}}function vrgs(f){var s=f+"",i=s.indexOf("...");return i>=0&&(i<s.indexOf(")")||s.indexOf("arguments")>=0)}function nanomemoize(fn,o){o||(o={});var vargs=o.vargs||vrgs(fn),s=Object.create(null),k=[],v=[],wm=new WeakMap,d=function(key,c,k){return setTimeout(function(){if(k){c.splice(key,1);k.splice(key,1);return}c instanceof WeakMap?c.delete(key):delete c[key]},o.maxAge)},c=o.maxAge>0&&o.maxAge<Infinity?d:0,eq=o.equals?o.equals:function(a,b){return a===b},maxargs=o.maxArgs,srlz=o.serializer,f,u;if(fn.length===1&&!o.equals&&!vargs){f=function(a){var t=typeof a;if(!srlz&&(t==="object"&&a||t==="function")){var r;return wm.get(a)||(!c||c(a,wm),wm.set(a,r=fn.call(this,a)),r)}var key=t==="number"||t==="boolean"||a==null?a:t==="string"?JSON.stringify(a):srlz(a);return s[key]||(!c||c(key,s),s[key]=fn.call(this,a))}.bind(this);u=1}else{f=function(){var l=maxargs||arguments.length,i;for(i=k.length-1;i>=0;i--){for(var j=l-1;j>=0&&eq(k[i][j],arguments[j]);j--){if(j===0){return v[i]}}}i=k.length-(i+1);return!c||c(i,v,k),v[i]=fn.apply(this,k[i]=arguments)}.bind(this)}f.clear=function(){wm=new WeakMap;s=Object.create(null);k=[];v=[]};f.keys=function(){return u?null:k.slice()};f.values=function(){return u?null:v.slice()};f.keyValues=function(){return u?{primitives:assign({},s),objects:wm}:null};return f}if(typeof module!=="undefined"){module.exports=nanomemoize}if(typeof window!=="undefined"){window.nanomemoize=nanomemoize}}).call(this); | ||
(function(){"use strict";var assign=Object.assign;if(typeof assign!=="function"){assign=function(){var a=arguments,o=arguments[0];if(o===null||o===undefined){throw new TypeError("Cannot convert undefined or null to object")}o=Object(o);for(var i=1;i<a.length;i++){if(a[i]&&typeof a[i]==="object"){for(var k in a[i]){o[k]=a[i][k]}}}return o}}function vrgs(f){var s=f+"",i=s.indexOf("...");return i>=0&&(i<s.indexOf(")")||s.indexOf("arguments")>=0)}function nanomemoize(fn,o){o||(o={});var vargs=o.vargs||vrgs(fn),s=Object.create(null),k=[],v=[],wm=new WeakMap,d=function(key,c,k){return setTimeout(function(){if(k){c.splice(key,1);k.splice(key,1);return}c instanceof WeakMap?c.delete(key):delete c[key]},o.maxAge)},c=o.maxAge>0&&o.maxAge<Infinity?d:0,eq=o.equals?o.equals:function(a,b){return a===b},maxargs=o.maxArgs,srlz=o.serializer,f,u;if(fn.length===1&&!o.equals&&!vargs){f=function(a){var t=typeof a;if(!srlz&&(t==="object"&&a||t==="function")){var r;return wm.get(a)||(!c||c(a,wm),wm.set(a,r=fn.call(this,a)),r)}var key=t==="number"||t==="boolean"||a==null?a:t==="string"?JSON.stringify(a):srlz(a);return s[key]||(!c||c(key,s),s[key]=fn.call(this,a))}.bind(this);u=1}else{f=function(){var l=maxargs||arguments.length,i;for(i=k.length-1;i>=0;i--){if(!maxargs&&k[i].length!==l)continue;for(var j=l-1;j>=0&&eq(k[i][j],arguments[j]);j--){if(j===0){return v[i]}}}i=k.length-(i+1);return!c||c(i,v,k),v[i]=fn.apply(this,k[i]=arguments)}.bind(this)}f.clear=function(){wm=new WeakMap;s=Object.create(null);k=[];v=[]};f.keys=function(){return u?null:k.slice()};f.values=function(){return u?null:v.slice()};f.keyValues=function(){return u?{primitives:assign({},s),objects:wm}:null};return f}if(typeof module!=="undefined"){module.exports=nanomemoize}if(typeof window!=="undefined"){window.nanomemoize=nanomemoize}}).call(this); |
@@ -77,2 +77,3 @@ (function() { | ||
for(i=k.length-1;i>=0;i--) { // an array of arrays of args, each array represents a call signature | ||
if (!maxargs && k[i].length !== l) continue; // cache miss if called with a different number of args | ||
for(var j=l-1;j>=0 && eq(k[i][j],arguments[j]);j--) { // compare each arg | ||
@@ -79,0 +80,0 @@ if(j===0) { return v[i]; } // the args matched |
{ | ||
"name": "nano-memoize", | ||
"version": "v1.1.11", | ||
"version": "v1.2.0", | ||
"description": "Faster than fast, smaller than micro ... a nano speed and nano size memoizer.", | ||
@@ -5,0 +5,0 @@ "engines": {}, |
@@ -21,3 +21,3 @@ [![Codacy Badge](https://api.codacy.com/project/badge/Grade/30ce201484754fa5b0a6c6046abb842d)](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 780 bytes for `nano-memoize` v1.1.5 vs 1,356 bytes for `micro-memoize` v4.08. And, `nano-memoize` has | ||
The minified/brotli size is 789 bytes for `nano-memoize` v1.1.5 vs 1,356 bytes for `micro-memoize` v4.08. And, `nano-memoize` has | ||
slightly more functionality. | ||
@@ -195,3 +195,7 @@ | ||
// only use the provided maxArgs for cache look-up, useful for ignoring final callback arguments | ||
maxArgs: number, | ||
maxArgs: number, | ||
// go ahead and call memoized multi-args functions after a number of milliseconds via a timeout after the | ||
// cached result has been returned, perhaps to ensure that callbacks are invoked, does not cache the timemout result | ||
// e.g. nanomemoize(function(a,b,cb) { var result = a + b; cb(result); return result; },{maxArgs:2,callTimeout:0}); | ||
callTimeout: number, | ||
// number of milliseconds to cache a result, set to `Infinity` or `-1` to never create timers or expire | ||
@@ -213,2 +217,4 @@ maxAge: number, | ||
2020-06-18 v1.2.0 Enhanced multi-arg handling so that arg lengths must match precisely (thanks @amazingmarvin), unless `maxArgs` is passed as an option. | ||
2020-05-26 v1.1.11 [Fixed Issue 17]Fixed https://github.com/anywhichway/nano-memoize/issues/17. It is not known when this bug made its way into the code. | ||
@@ -215,0 +221,0 @@ |
@@ -77,2 +77,3 @@ (function() { | ||
for(i=k.length-1;i>=0;i--) { // an array of arrays of args, each array represents a call signature | ||
if (!maxargs && k[i].length !== l) continue; // cache miss if called with a different number of args | ||
for(var j=l-1;j>=0 && eq(k[i][j],arguments[j]);j--) { // compare each arg | ||
@@ -79,0 +80,0 @@ if(j===0) { return v[i]; } // the args matched |
@@ -24,2 +24,3 @@ var chai, | ||
callTimeout = nanomemoize(function(a,b,cb) { var result = a + b; cb(result); return result; },{maxArgs:2,callTimeout:0}); | ||
@@ -95,2 +96,16 @@ describe("Test",function() { | ||
}); | ||
it("multiple varg mixed length",function() { | ||
const res1 = varArg("multi1", "multi2"); | ||
const res2 = varArg("multi1"); | ||
expect(res1).to.not.equal(res2); | ||
}); | ||
it("callTimeout",function(done) { | ||
let result = 0; | ||
const res1 = callTimeout(1,2,(value) => result = value + 1); | ||
expect(res1).to.equal(3); | ||
setTimeout(() => { | ||
expect(result).to.equal(4); | ||
done(); | ||
},100) | ||
}); | ||
it("auto-detect vArg",function() { | ||
@@ -97,0 +112,0 @@ const arg1 = 1, arg2 = 2; |
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
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
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
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
76678
997
283