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

nano-memoize

Package Overview
Dependencies
Maintainers
1
Versions
51
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nano-memoize - npm Package Compare versions

Comparing version 1.0.3 to 1.0.4

12

browser/nano-memoize.js

@@ -24,4 +24,4 @@ (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){

const key = (!arg || typeof arg === "number" || typeof arg ==="boolean" ? arg : serializer(arg));
if(chng) chng(key);
return s[key] || (s[key] = f.call(this, arg));
// 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] || (chng(key),s[key] = f.call(this, arg));
}

@@ -47,4 +47,4 @@ // for multiple arg functions, loop through a cache of all the args

const i = rslt.i>=0 ? rslt.i : v.length;
if(chng) chng(i);
return typeof rslt.v === "undefined" ? v[i] = f.call(this,...(k[i] = args)) : rslt.v;
// set chng timeout only when new value computed, hits will not push out the tte, but it is arguable they should not
return typeof rslt.v === "undefined" || rslt.v === undefined ? (chng(i),v[i] = f.call(this,...(k[i] = args))) : rslt.v;
}

@@ -59,3 +59,3 @@ let m,

s,
maxAge ? (key) => setTimeout(() => { delete s[key]; },maxAge) : null,
maxAge ? (key) => setTimeout(() => { delete s[key]; },maxAge) : ()=>{},
serializer

@@ -70,3 +70,3 @@ );

equals || ((a,b) => a===b), // default to just a regular strict comparison
maxAge ? (key) => setTimeout(() => { delete v[key]; },maxAge) : null,
maxAge ? (key) => setTimeout(() => { delete v[key]; },maxAge) : ()=>{},
maxArgs

@@ -73,0 +73,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 hsVrgs=f=>{const s=f+"",i=s.indexOf("...");return i>=0&&i<s.indexOf(")"||s.indexOf("arguments")>=0)};function nanomemoize(fn,options={}){const{serializer:serializer=(value=>JSON.stringify(value)),equals:equals,maxAge:maxAge,maxArgs:maxArgs,vargs:vargs=hsVrgs(fn)}=options,s={},k=[],v=[];function sngl(f,s,chng,serializer,arg){const key=!arg||typeof arg==="number"||typeof arg==="boolean"?arg:serializer(arg);if(chng)chng(key);return s[key]||(s[key]=f.call(this,arg))}function mltpl(f,k,v,eq,chng,max=0,...args){const rslt={};for(let i=0;i<k.length;i++){let key=k[i];if(max){key=key.slice(0,max)}if(key.length===args.length||max&&key.length<args.length){const max=key.length-1;for(let j=0;j<=max;j++){if(!eq(key[j],args[j])){break}if(j===max){rslt.i=i;rslt.v=v[i]}}}}const i=rslt.i>=0?rslt.i:v.length;if(chng)chng(i);return typeof rslt.v==="undefined"?v[i]=f.call(this,...k[i]=args):rslt.v}let m,unry=fn.length===1&&!equals&&!vargs;if(unry){m=sngl.bind(this,fn,s,maxAge?key=>setTimeout(()=>{delete s[key]},maxAge):null,serializer)}else{m=mltpl.bind(this,fn,k,v,equals||((a,b)=>a===b),maxAge?key=>setTimeout(()=>{delete v[key]},maxAge):null,maxArgs)}m.clear=(()=>{Object.keys(s).forEach(k=>delete s[k]);k.length=0;v.length=0});m.keys=(()=>!unry?k.slice():null);m.values=(()=>!unry?v.slice():null);m.keyValues=(()=>unry?Object.assign({},s):null);return m}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 hsVrgs=f=>{const s=f+"",i=s.indexOf("...");return i>=0&&i<s.indexOf(")"||s.indexOf("arguments")>=0)};function nanomemoize(fn,options={}){const{serializer:serializer=(value=>JSON.stringify(value)),equals:equals,maxAge:maxAge,maxArgs:maxArgs,vargs:vargs=hsVrgs(fn)}=options,s={},k=[],v=[];function sngl(f,s,chng,serializer,arg){const key=!arg||typeof arg==="number"||typeof arg==="boolean"?arg:serializer(arg);return s[key]||(chng(key),s[key]=f.call(this,arg))}function mltpl(f,k,v,eq,chng,max=0,...args){const rslt={};for(let i=0;i<k.length;i++){let key=k[i];if(max){key=key.slice(0,max)}if(key.length===args.length||max&&key.length<args.length){const max=key.length-1;for(let j=0;j<=max;j++){if(!eq(key[j],args[j])){break}if(j===max){rslt.i=i;rslt.v=v[i]}}}}const i=rslt.i>=0?rslt.i:v.length;return typeof rslt.v==="undefined"||rslt.v===undefined?(chng(i),v[i]=f.call(this,...k[i]=args)):rslt.v}let m,unry=fn.length===1&&!equals&&!vargs;if(unry){m=sngl.bind(this,fn,s,maxAge?key=>setTimeout(()=>{delete s[key]},maxAge):()=>{},serializer)}else{m=mltpl.bind(this,fn,k,v,equals||((a,b)=>a===b),maxAge?key=>setTimeout(()=>{delete v[key]},maxAge):()=>{},maxArgs)}m.clear=(()=>{Object.keys(s).forEach(k=>delete s[k]);k.length=0;v.length=0});m.keys=(()=>!unry?k.slice():null);m.values=(()=>!unry?v.slice():null);m.keyValues=(()=>unry?Object.assign({},s):null);return m}if(typeof module!=="undefined")module.exports=nanomemoize;if(typeof window!=="undefined")window.nanomemoize=nanomemoize}).call(this)},{}]},{},[1]);

@@ -23,4 +23,4 @@ (function() {

const key = (!arg || typeof arg === "number" || typeof arg ==="boolean" ? arg : serializer(arg));
if(chng) chng(key);
return s[key] || (s[key] = f.call(this, arg));
// 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] || (chng(key),s[key] = f.call(this, arg));
}

@@ -46,4 +46,4 @@ // for multiple arg functions, loop through a cache of all the args

const i = rslt.i>=0 ? rslt.i : v.length;
if(chng) chng(i);
return typeof rslt.v === "undefined" ? v[i] = f.call(this,...(k[i] = args)) : rslt.v;
// set chng timeout only when new value computed, hits will not push out the tte, but it is arguable they should not
return typeof rslt.v === "undefined" || rslt.v === undefined ? (chng(i),v[i] = f.call(this,...(k[i] = args))) : rslt.v;
}

@@ -58,3 +58,3 @@ let m,

s,
maxAge ? (key) => setTimeout(() => { delete s[key]; },maxAge) : null,
maxAge ? (key) => setTimeout(() => { delete s[key]; },maxAge) : ()=>{},
serializer

@@ -69,3 +69,3 @@ );

equals || ((a,b) => a===b), // default to just a regular strict comparison
maxAge ? (key) => setTimeout(() => { delete v[key]; },maxAge) : null,
maxAge ? (key) => setTimeout(() => { delete v[key]; },maxAge) : ()=>{},
maxArgs

@@ -72,0 +72,0 @@ );

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

(function(){"use strict";const hsVrgs=f=>{const s=f+"",i=s.indexOf("...");return i>=0&&i<s.indexOf(")"||s.indexOf("arguments")>=0)};function nanomemoize(fn,options={}){const{serializer:serializer=(value=>JSON.stringify(value)),equals:equals,maxAge:maxAge,maxArgs:maxArgs,vargs:vargs=hsVrgs(fn)}=options,s={},k=[],v=[];function sngl(f,s,chng,serializer,arg){const key=!arg||typeof arg==="number"||typeof arg==="boolean"?arg:serializer(arg);if(chng)chng(key);return s[key]||(s[key]=f.call(this,arg))}function mltpl(f,k,v,eq,chng,max=0,...args){const rslt={};for(let i=0;i<k.length;i++){let key=k[i];if(max){key=key.slice(0,max)}if(key.length===args.length||max&&key.length<args.length){const max=key.length-1;for(let j=0;j<=max;j++){if(!eq(key[j],args[j])){break}if(j===max){rslt.i=i;rslt.v=v[i]}}}}const i=rslt.i>=0?rslt.i:v.length;if(chng)chng(i);return typeof rslt.v==="undefined"?v[i]=f.call(this,...k[i]=args):rslt.v}let m,unry=fn.length===1&&!equals&&!vargs;if(unry){m=sngl.bind(this,fn,s,maxAge?key=>setTimeout(()=>{delete s[key]},maxAge):null,serializer)}else{m=mltpl.bind(this,fn,k,v,equals||((a,b)=>a===b),maxAge?key=>setTimeout(()=>{delete v[key]},maxAge):null,maxArgs)}m.clear=(()=>{Object.keys(s).forEach(k=>delete s[k]);k.length=0;v.length=0});m.keys=(()=>!unry?k.slice():null);m.values=(()=>!unry?v.slice():null);m.keyValues=(()=>unry?Object.assign({},s):null);return m}if(typeof module!=="undefined")module.exports=nanomemoize;if(typeof window!=="undefined")window.nanomemoize=nanomemoize}).call(this);
(function(){"use strict";const hsVrgs=f=>{const s=f+"",i=s.indexOf("...");return i>=0&&i<s.indexOf(")"||s.indexOf("arguments")>=0)};function nanomemoize(fn,options={}){const{serializer:serializer=(value=>JSON.stringify(value)),equals:equals,maxAge:maxAge,maxArgs:maxArgs,vargs:vargs=hsVrgs(fn)}=options,s={},k=[],v=[];function sngl(f,s,chng,serializer,arg){const key=!arg||typeof arg==="number"||typeof arg==="boolean"?arg:serializer(arg);return s[key]||(chng(key),s[key]=f.call(this,arg))}function mltpl(f,k,v,eq,chng,max=0,...args){const rslt={};for(let i=0;i<k.length;i++){let key=k[i];if(max){key=key.slice(0,max)}if(key.length===args.length||max&&key.length<args.length){const max=key.length-1;for(let j=0;j<=max;j++){if(!eq(key[j],args[j])){break}if(j===max){rslt.i=i;rslt.v=v[i]}}}}const i=rslt.i>=0?rslt.i:v.length;return typeof rslt.v==="undefined"||rslt.v===undefined?(chng(i),v[i]=f.call(this,...k[i]=args)):rslt.v}let m,unry=fn.length===1&&!equals&&!vargs;if(unry){m=sngl.bind(this,fn,s,maxAge?key=>setTimeout(()=>{delete s[key]},maxAge):()=>{},serializer)}else{m=mltpl.bind(this,fn,k,v,equals||((a,b)=>a===b),maxAge?key=>setTimeout(()=>{delete v[key]},maxAge):()=>{},maxArgs)}m.clear=(()=>{Object.keys(s).forEach(k=>delete s[k]);k.length=0;v.length=0});m.keys=(()=>!unry?k.slice():null);m.values=(()=>!unry?v.slice():null);m.keyValues=(()=>unry?Object.assign({},s):null);return m}if(typeof module!=="undefined")module.exports=nanomemoize;if(typeof window!=="undefined")window.nanomemoize=nanomemoize}).call(this);

@@ -23,4 +23,4 @@ (function() {

const key = (!arg || typeof arg === "number" || typeof arg ==="boolean" ? arg : serializer(arg));
if(chng) chng(key);
return s[key] || (s[key] = f.call(this, arg));
// 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] || (chng(key),s[key] = f.call(this, arg));
}

@@ -46,4 +46,4 @@ // for multiple arg functions, loop through a cache of all the args

const i = rslt.i>=0 ? rslt.i : v.length;
if(chng) chng(i);
return typeof rslt.v === "undefined" ? v[i] = f.call(this,...(k[i] = args)) : rslt.v;
// set chng timeout only when new value computed, hits will not push out the tte, but it is arguable they should not
return typeof rslt.v === "undefined" || rslt.v === undefined ? (chng(i),v[i] = f.call(this,...(k[i] = args))) : rslt.v;
}

@@ -58,3 +58,3 @@ let m,

s,
maxAge ? (key) => setTimeout(() => { delete s[key]; },maxAge) : null,
maxAge ? (key) => setTimeout(() => { delete s[key]; },maxAge) : ()=>{},
serializer

@@ -69,3 +69,3 @@ );

equals || ((a,b) => a===b), // default to just a regular strict comparison
maxAge ? (key) => setTimeout(() => { delete v[key]; },maxAge) : null,
maxAge ? (key) => setTimeout(() => { delete v[key]; },maxAge) : ()=>{},
maxArgs

@@ -72,0 +72,0 @@ );

{
"name": "nano-memoize",
"version": "v1.0.3",
"version": "v1.0.4",
"description": "Faster than fast, smaller than micro ... a nano speed and nano size memoizer.",

@@ -5,0 +5,0 @@ "engines": {},

@@ -8,3 +8,3 @@ [![Codacy Badge](https://api.codacy.com/project/badge/Grade/30ce201484754fa5b0a6c6046abb842d)](https://www.codacy.com/app/syblackwell/nano-memoize?utm_source=github.com&amp;utm_medium=referral&amp;utm_content=anywhichway/nano-memoize&amp;utm_campaign=Badge_Grade)

The minified/gzipped size is 589 bytes for `nano-memoize` vs 959 bytes for `micro-memoize`. And, `nano-memoize` has slightly more functionality.
The minified/gzipped size is 592 bytes for `nano-memoize` vs 959 bytes for `micro-memoize`. And, `nano-memoize` has slightly more functionality.

@@ -15,9 +15,9 @@ The speed tests are below. In most cases `nano-memoize` is the fastest.

* For single object argument functions it is always by far the fastest.
* For single object argument functions it is typically 2x faster than anything else.
* For multiple primitive argument functions functions`nano-memoize` slightly and probably un-importantly faster than `fast-memoize`.
* For multiple object argument functions `fast-memoize` slightly and probably un-importantly faster.
* For multiple object argument functions `micro-memoize` is slightly and probably un-importantly faster.
We have found that benchmarks can vary dramatically from O/S to O/S or Node version to Node version. These tests were run on a Windows 10 64bit 2.4ghz machine with 8GB RAM and Node v9.4.0. Also, even with multiple samplings, garbage collection can have a substative impact and multiple runs in different orders are really required for apples-to-apples comparisons.
We have found that benchmarks can vary dramatically from O/S to O/S or Node version to Node version. These tests were run on a Windows 10 64bit 2.4ghz machine with 8GB RAM and Node v11.6.0. Also, even with multiple samplings, garbage collection can have a substative impact and multiple runs in different orders are really required for apples-to-apples comparisons.

@@ -195,5 +195,7 @@ Functions with a single primitive parameter...

2019-02-26 v1.0.4 Further optimized cache expiration. See [Issue 4](https://github.com/anywhichway/nano-memoize/issues/4)
2019-02-16 v1.0.3 Fixed README formatting
2019-02-16 v1.0.2 Further optimizations to deal with Issue 4. `expireInterval` introduced in v1.0.1 removed since it is no longer needed. Also, 25% reduction in size. Code no longer thrashes when memoizing a large number of functions.
2019-02-16 v1.0.2 Further optimizations to deal with [Issue 4](https://github.com/anywhichway/nano-memoize/issues/4). `expireInterval` introduced in v1.0.1 removed since it is no longer needed. Also, 25% reduction in size. Code no longer thrashes when memoizing a large number of functions.

@@ -200,0 +202,0 @@ 2019-02-16 v1.0.1 Memo expiration optimization. Issue 4 addressed.

@@ -23,4 +23,4 @@ (function() {

const key = (!arg || typeof arg === "number" || typeof arg ==="boolean" ? arg : serializer(arg));
if(chng) chng(key);
return s[key] || (s[key] = f.call(this, arg));
// 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] || (chng(key),s[key] = f.call(this, arg));
}

@@ -46,4 +46,4 @@ // for multiple arg functions, loop through a cache of all the args

const i = rslt.i>=0 ? rslt.i : v.length;
if(chng) chng(i);
return typeof rslt.v === "undefined" ? v[i] = f.call(this,...(k[i] = args)) : rslt.v;
// set chng timeout only when new value computed, hits will not push out the tte, but it is arguable they should not
return typeof rslt.v === "undefined" || rslt.v === undefined ? (chng(i),v[i] = f.call(this,...(k[i] = args))) : rslt.v;
}

@@ -58,3 +58,3 @@ let m,

s,
maxAge ? (key) => setTimeout(() => { delete s[key]; },maxAge) : null,
maxAge ? (key) => setTimeout(() => { delete s[key]; },maxAge) : ()=>{},
serializer

@@ -69,3 +69,3 @@ );

equals || ((a,b) => a===b), // default to just a regular strict comparison
maxAge ? (key) => setTimeout(() => { delete v[key]; },maxAge) : null,
maxAge ? (key) => setTimeout(() => { delete v[key]; },maxAge) : ()=>{},
maxArgs

@@ -72,0 +72,0 @@ );

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