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

memoizerific

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

memoizerific - npm Package Compare versions

Comparing version 1.8.4 to 1.8.6

tests/surpassed-limit.js

120

memoizerific.js
(function(f){if(typeof exports==="object"&&typeof module!=="undefined"){module.exports=f()}else if(typeof define==="function"&&define.amd){define([],f)}else{var g;if(typeof window!=="undefined"){g=window}else if(typeof global!=="undefined"){g=global}else if(typeof self!=="undefined"){g=self}else{g=this}g.memoizerific = f()}})(function(){var define,module,exports;return (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(_dereq_,module,exports){
if (typeof Map !== 'function' || (process && process.env && process.env.TEST_MAPORSIMILAR === 'true')) {
module.exports = _dereq_('./similar');
}
else {
module.exports = Map;
}
},{"./similar":2}],2:[function(_dereq_,module,exports){
function Similar() {
this.list = [];
this.lastItem = undefined;
this.size = 0;
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var i;i="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,i.mapOrSimilar=t()}}(function(){var t,i,e;return function t(i,e,s){function n(o,l){if(!e[o]){if(!i[o]){var a="function"==typeof _dereq_&&_dereq_;if(!l&&a)return a(o,!0);if(r)return r(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var h=e[o]={exports:{}};i[o][0].call(h.exports,function(t){var e=i[o][1][t];return n(e?e:t)},h,h.exports,t,i,e,s)}return e[o].exports}for(var r="function"==typeof _dereq_&&_dereq_,o=0;o<s.length;o++)n(s[o]);return n}({1:[function(t,i,e){i.exports=function(i){if("function"!=typeof Map||i){var e=t("./similar");return new e}return new Map}},{"./similar":2}],2:[function(t,i,e){function s(){return this.list=[],this.lastItem=void 0,this.size=0,this}s.prototype.get=function(t){var i;return this.lastItem&&this.isEqual(this.lastItem.key,t)?this.lastItem.val:(i=this.indexOf(t),i>=0?(this.lastItem=this.list[i],this.list[i].val):void 0)},s.prototype.set=function(t,i){var e;return this.lastItem&&this.isEqual(this.lastItem.key,t)?(this.lastItem.val=i,this):(e=this.indexOf(t),e>=0?(this.lastItem=this.list[e],this.list[e].val=i,this):(this.lastItem={key:t,val:i},this.list.push(this.lastItem),this.size++,this))},s.prototype.delete=function(t){var i;if(this.lastItem&&this.isEqual(this.lastItem.key,t)&&(this.lastItem=void 0),i=this.indexOf(t),i>=0)return this.size--,this.list.splice(i,1)[0]},s.prototype.has=function(t){var i;return!(!this.lastItem||!this.isEqual(this.lastItem.key,t))||(i=this.indexOf(t),i>=0&&(this.lastItem=this.list[i],!0))},s.prototype.forEach=function(t,i){var e;for(e=0;e<this.size;e++)t.call(i||this,this.list[e].val,this.list[e].key,this)},s.prototype.indexOf=function(t){var i;for(i=0;i<this.size;i++)if(this.isEqual(this.list[i].key,t))return i;return-1},s.prototype.isEqual=function(t,i){return t===i||t!==t&&i!==i},i.exports=s},{}]},{},[1])(1)});
return this;
}
Similar.prototype.get = function(key) {
var index;
if (this.lastItem && this.isEqual(this.lastItem.key, key)) {
return this.lastItem.val;
}
index = this.indexOf(key);
if (index >= 0) {
this.lastItem = this.list[index];
return this.list[index].val;
}
return undefined;
};
Similar.prototype.set = function(key, val) {
var index;
if (this.lastItem && this.isEqual(this.lastItem.key, key)) {
this.lastItem.val = val;
return this;
}
index = this.indexOf(key);
if (index >= 0) {
this.lastItem = this.list[index];
this.list[index].val = val;
return this;
}
this.lastItem = { key: key, val: val };
this.list.push(this.lastItem);
this.size++;
return this;
};
Similar.prototype.delete = function(key) {
var index;
if (this.lastItem && this.isEqual(this.lastItem.key, key)) {
this.lastItem = undefined;
}
index = this.indexOf(key);
if (index >= 0) {
this.size--;
return this.list.splice(index, 1)[0];
}
return undefined;
};
// important that has() doesn't use get() in case an existing key has a falsy value, in which case has() would return false
Similar.prototype.has = function(key) {
var index;
if (this.lastItem && this.isEqual(this.lastItem.key, key)) {
return true;
}
index = this.indexOf(key);
if (index >= 0) {
this.lastItem = this.list[index];
return true;
}
return false;
};
Similar.prototype.forEach = function(callback, thisArg) {
var i;
for (i = 0; i < this.size; i++) {
callback.call(thisArg || this, this.list[i].val, this.list[i].key, this);
}
};
Similar.prototype.indexOf = function(key) {
var i;
for (i = 0; i < this.size; i++) {
if (this.isEqual(this.list[i].key, key)) {
return i;
}
}
return -1;
};
// check if the numbers are equal, or whether they are both precisely NaN (isNaN returns true for all non-numbers)
Similar.prototype.isEqual = function(val1, val2) {
return val1 === val2 || (val1 !== val1 && val2 !== val2);
};
module.exports = Similar;
},{}],3:[function(_dereq_,module,exports){
},{}],2:[function(_dereq_,module,exports){
var MapOrSimilar = _dereq_('map-or-similar');
module.exports = function (limit) {
var cache = new MapOrSimilar(),
var cache = new MapOrSimilar(undefined === 'true'),
lru = [];

@@ -141,3 +33,3 @@

// climb through the hierarchical map tree until the second-last argument has been found, or an argument is missing.
// if all arguments up to the second-last have been found, this will potentially be a cache hit (determined below)
// if all arguments up to the second-last have been found, this will potentially be a cache hit (determined later)
if (currentCache.has(arguments[i])) {

@@ -151,3 +43,3 @@ currentCache = currentCache.get(arguments[i]);

// make maps until last value
newMap = new MapOrSimilar();
newMap = new MapOrSimilar(undefined === 'true');
currentCache.set(arguments[i], newMap);

@@ -254,3 +146,3 @@ currentCache = newMap;

}
},{"map-or-similar":1}]},{},[3])(3)
},{"map-or-similar":1}]},{},[2])(2)
});

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

��gbW�VKo�8�﯐}pE����M*c�,P�i}� �`�Qĭ$�$�4���w(J��x�����{���$���Y���D�O��ߐ�)c��z����lZ�[HE �餿,�΁���ce�'�<������f�?�Ŗ�����q��{�<����� ʭ|X����].oy�vg94�����&�BP@!�P"���i�!5�u�P�"R`jUz��g|�RMvE���6����;A{�jrv&'
��BaR�Cde�l���^�J'Kb�eO+;��Z��+�����Ð�]��ӹ�O_LId2%�:H��{}���/�o>}�����7SZ7V_Ƭ�l��4�5Mdc�,� �y�g}��1���`-�*ޘ�O���Z��44��6�����&��&�H�����J���k�Pޙ,��9Q��I\h��*������|��5���J�4�;P�cU����������\_�u������.?��{a��E!r��$<\����.×ML_>up��Fv�X��Іٖi?�6o �^���tD��f���]6҆܁a�U�h��S7���B_}�y�������|`N ���M�&(\��z,φ(6�G�>��H2Ǯ��:����������O��F!���X�Xh��CCm��9HU��1+9�r>w�NR�� ����f�9Ha ���up�8
EW�H������9v=��q��)�� '�������Ivkv2 �7��y$p�7a�ow�)Ƅ�g[ͱ���3Y�V��#8��� �Τ�k$��~a��]�N�:ѓ`�2ള!Mp��f�����8�pp�zvp��L7��f�ō�hǸ�����Y�b�%�H�<�.� ����Ww�A��d�*�_�S����!);H6G+�O��?tu�UL5U��X�$�q��d�R�`�2R4�+�P�����'z�����nZ,ȿ�=�����K�m
^-�Z +':�� ��7��H7��_-g'� ;�j��)C�J�/�Ŋ&�R)�����-]a_,>ʺ�Tw��>q� g Ê����c���a6��=��:�z<��ڻ��l�qh2�i^���o3�z���[�1�^Q��J6>u�*�9E�p��ۆ�vX��4��Y�VvD } |E�.��]Y#Z��zx�T�S�)jϞhGjh�cn�{?ce��*��:o]vl��4��Era���s��l�־� �k�W_W� ������ɨ�\wUڲ����Y���q*�0s"���ZȤj&(o�<:As�jb;o��UL�W�!�o�2v��
���JX�WM��6��W�>8$L���e�������0�L��H�BR�lm��EI�lm���� ����p<K+�X�$��(R4W���)��%Wi���J[�X�+y੐�0�u u�r��#lU�E8�ၳ��?[�V � Yq�~�v{b���W�s:��Iȃz��G4���o�cR��<ݺ��f��P�/�E*�A]�܄c '"��VZݷ�"����D"E�̙ة�_�f��0:���_*��v�=�b�p돁��;��d��9���)��Zi4��I�l)�o�K������fZ=U��������_�>�v�ǧ��?��~N���˩��ۚFǺ�]��>LX���+72�m�Q��wv��%�؊���伳A��[-��X���3g� ^D�u�nu�s�h�X-�X"�@�C��q��h۲�΂����/�� ϿOx�X؆��1�.c�1\�+���9�.�)�$ )����y�w��z�2����ʳ�-U��
��V�L�2��WY�Y����auF]�cV��{Vg/���Fq�j���7��H6`�ǫc�sy�j�F$&���cr
L6H:p{�Ln�>��%�{O=9>��t��y�h�h<3��Ћz�����M�'7ס�L���ւca� c�k�� 3�� �U�C��BM��u��R+�\��#���&��vkN�{��K�r4�~��p�l�¯p��~��o�)� �-]o��i�ŎwY�gG> �0t3
�t�����U��7����,�w��,�~ll���#KX�>�
��dcU|.�r�]@r�9�|��@���b������(��B\�ɘ2 ��a��)��Θy��34q:�^ �N/��*���;^� ]�%�$�\��S�m�q,��X�������, ��]�~۰'Pq^��|�Ȁ���qi�P K[����©�z�lWUJ�KiM�)<���Ψ��{�C��c��5nD�t�3�Զ���%�-%������!�@�N �l��t�4swd݈�ӏ�� �����4g�kГ�/�3ֱSyv�z0s��T�����]F�P�$� ���K$嫛Xz�}vѡ>��Ny��ܺ))��j�_�[&�׊�/E��`LY)�:_G�Z�����m����r9����� ����T0�f¬
.�iQ[mHB�i͞Q���+_��JCY���9�֐@�
�_C*n��F�ˇ���><�LU�!`�{6�ܑ���l ��<��I�>Z��U�^�Y\��]�M_��Ў��&��04��-����H!H|C����c#-R��V��Py.=d�!����9|��Ԅ�,�g$�<'�ڵ�lOr ��[��^��p �[�=Ip$�J�(m����oIh2���=0��O̴�:В�Uu5� ��4�BXj/v`�?
@/P�$�����Ѧ�B7Ѕn� �?� �˥�

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

!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.memoizerific=t()}}(function(){var t,e,i;return function t(e,i,s){function r(o,a){if(!i[o]){if(!e[o]){var l="function"==typeof require&&require;if(!a&&l)return l(o,!0);if(n)return n(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}var h=i[o]={exports:{}};e[o][0].call(h.exports,function(t){var i=e[o][1][t];return r(i?i:t)},h,h.exports,t,e,i,s)}return i[o].exports}for(var n="function"==typeof require&&require,o=0;o<s.length;o++)r(s[o]);return r}({1:[function(t,e,i){"function"!=typeof Map||process&&process.env&&"true"===process.env.TEST_MAPORSIMILAR?e.exports=t("./similar"):e.exports=Map},{"./similar":2}],2:[function(t,e,i){function s(){return this.list=[],this.lastItem=void 0,this.size=0,this}s.prototype.get=function(t){var e;return this.lastItem&&this.isEqual(this.lastItem.key,t)?this.lastItem.val:(e=this.indexOf(t),e>=0?(this.lastItem=this.list[e],this.list[e].val):void 0)},s.prototype.set=function(t,e){var i;return this.lastItem&&this.isEqual(this.lastItem.key,t)?(this.lastItem.val=e,this):(i=this.indexOf(t),i>=0?(this.lastItem=this.list[i],this.list[i].val=e,this):(this.lastItem={key:t,val:e},this.list.push(this.lastItem),this.size++,this))},s.prototype.delete=function(t){var e;return this.lastItem&&this.isEqual(this.lastItem.key,t)&&(this.lastItem=void 0),e=this.indexOf(t),e>=0?(this.size--,this.list.splice(e,1)[0]):void 0},s.prototype.has=function(t){var e;return this.lastItem&&this.isEqual(this.lastItem.key,t)?!0:(e=this.indexOf(t),e>=0?(this.lastItem=this.list[e],!0):!1)},s.prototype.forEach=function(t,e){var i;for(i=0;i<this.size;i++)t.call(e||this,this.list[i].val,this.list[i].key,this)},s.prototype.indexOf=function(t){var e;for(e=0;e<this.size;e++)if(this.isEqual(this.list[e].key,t))return e;return-1},s.prototype.isEqual=function(t,e){return t===e||t!==t&&e!==e},e.exports=s},{}],3:[function(t,e,i){function s(t,e){var i=t.length,s=e.length,r,o,a;for(o=0;i>o;o++){for(r=!0,a=0;s>a;a++)if(!n(t[o][a].arg,e[a].arg)){r=!1;break}if(r)break}t.push(t.splice(o,1)[0])}function r(t){var e=t.length,i=t[e-1],s,r;for(i.cacheItem.delete(i.arg),r=e-2;r>=0&&(i=t[r],s=i.cacheItem.get(i.arg),!s||!s.size);r--)i.cacheItem.delete(i.arg)}function n(t,e){return t===e||t!==t&&e!==e}var o=t("map-or-similar");e.exports=function(t){var e=new o,i=[];return function(n){var a=function(){var l=e,u,h,f=arguments.length-1,c=Array(f+1),p=!0,m;if((a.numArgs||0===a.numArgs)&&a.numArgs!==f+1)throw new Error("Memoizerific functions should always be called with the same number of arguments");for(m=0;f>m;m++)c[m]={cacheItem:l,arg:arguments[m]},l.has(arguments[m])?l=l.get(arguments[m]):(p=!1,u=new o,l.set(arguments[m],u),l=u);return p&&(l.has(arguments[f])?h=l.get(arguments[f]):p=!1),p||(h=n.apply(null,arguments),l.set(arguments[f],h)),t>0&&(c[f]={cacheItem:l,arg:arguments[f]},p?s(i,c):i.push(c),i.length>t&&r(i.shift())),a.wasMemoized=p,a.numArgs=f+1,h};return a.limit=t,a.wasMemoized=!1,a.cache=e,a.lru=i,a}}},{"map-or-similar":1}]},{},[3])(3)});
!function(t){if("object"==typeof exports&&"undefined"!=typeof module)module.exports=t();else if("function"==typeof define&&define.amd)define([],t);else{var e;e="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,e.memoizerific=t()}}(function(){var t,e,i;return function t(e,i,r){function n(o,f){if(!i[o]){if(!e[o]){var a="function"==typeof require&&require;if(!f&&a)return a(o,!0);if(s)return s(o,!0);var u=new Error("Cannot find module '"+o+"'");throw u.code="MODULE_NOT_FOUND",u}var l=i[o]={exports:{}};e[o][0].call(l.exports,function(t){var i=e[o][1][t];return n(i?i:t)},l,l.exports,t,e,i,r)}return i[o].exports}for(var s="function"==typeof require&&require,o=0;o<r.length;o++)n(r[o]);return n}({1:[function(e,i,r){!function(e){if("object"==typeof r&&"undefined"!=typeof i)i.exports=e();else if("function"==typeof t&&t.amd)t([],e);else{var n;n="undefined"!=typeof window?window:"undefined"!=typeof global?global:"undefined"!=typeof self?self:this,n.mapOrSimilar=e()}}(function(){var t,i,r;return function t(i,r,n){function s(f,a){if(!r[f]){if(!i[f]){var u="function"==typeof e&&e;if(!a&&u)return u(f,!0);if(o)return o(f,!0);var l=new Error("Cannot find module '"+f+"'");throw l.code="MODULE_NOT_FOUND",l}var h=r[f]={exports:{}};i[f][0].call(h.exports,function(t){var e=i[f][1][t];return s(e?e:t)},h,h.exports,t,i,r,n)}return r[f].exports}for(var o="function"==typeof e&&e,f=0;f<n.length;f++)s(n[f]);return s}({1:[function(t,e,i){e.exports=function(e){if("function"!=typeof Map||e){var i=t("./similar");return new i}return new Map}},{"./similar":2}],2:[function(t,e,i){function r(){return this.list=[],this.lastItem=void 0,this.size=0,this}r.prototype.get=function(t){var e;return this.lastItem&&this.isEqual(this.lastItem.key,t)?this.lastItem.val:(e=this.indexOf(t),e>=0?(this.lastItem=this.list[e],this.list[e].val):void 0)},r.prototype.set=function(t,e){var i;return this.lastItem&&this.isEqual(this.lastItem.key,t)?(this.lastItem.val=e,this):(i=this.indexOf(t),i>=0?(this.lastItem=this.list[i],this.list[i].val=e,this):(this.lastItem={key:t,val:e},this.list.push(this.lastItem),this.size++,this))},r.prototype.delete=function(t){var e;if(this.lastItem&&this.isEqual(this.lastItem.key,t)&&(this.lastItem=void 0),e=this.indexOf(t),e>=0)return this.size--,this.list.splice(e,1)[0]},r.prototype.has=function(t){var e;return!(!this.lastItem||!this.isEqual(this.lastItem.key,t))||(e=this.indexOf(t),e>=0&&(this.lastItem=this.list[e],!0))},r.prototype.forEach=function(t,e){var i;for(i=0;i<this.size;i++)t.call(e||this,this.list[i].val,this.list[i].key,this)},r.prototype.indexOf=function(t){var e;for(e=0;e<this.size;e++)if(this.isEqual(this.list[e].key,t))return e;return-1},r.prototype.isEqual=function(t,e){return t===e||t!==t&&e!==e},e.exports=r},{}]},{},[1])(1)})},{}],2:[function(t,e,i){function r(t,e){var i=t.length,r=e.length,n,o,f;for(o=0;o<i;o++){for(n=!0,f=0;f<r;f++)if(!s(t[o][f].arg,e[f].arg)){n=!1;break}if(n)break}t.push(t.splice(o,1)[0])}function n(t){var e=t.length,i=t[e-1],r,n;for(i.cacheItem.delete(i.arg),n=e-2;n>=0&&(i=t[n],r=i.cacheItem.get(i.arg),!r||!r.size);n--)i.cacheItem.delete(i.arg)}function s(t,e){return t===e||t!==t&&e!==e}var o=t("map-or-similar");e.exports=function(t){var e=new o(!1),i=[];return function(s){var f=function(){var a=e,u,l,h=arguments.length-1,c=Array(h+1),p=!0,m;if((f.numArgs||0===f.numArgs)&&f.numArgs!==h+1)throw new Error("Memoizerific functions should always be called with the same number of arguments");for(m=0;m<h;m++)c[m]={cacheItem:a,arg:arguments[m]},a.has(arguments[m])?a=a.get(arguments[m]):(p=!1,u=new o(!1),a.set(arguments[m],u),a=u);return p&&(a.has(arguments[h])?l=a.get(arguments[h]):p=!1),p||(l=s.apply(null,arguments),a.set(arguments[h],l)),t>0&&(c[h]={cacheItem:a,arg:arguments[h]},p?r(i,c):i.push(c),i.length>t&&n(i.shift())),f.wasMemoized=p,f.numArgs=h+1,l};return f.limit=t,f.wasMemoized=!1,f.cache=e,f.lru=i,f}}},{"map-or-similar":1}]},{},[2])(2)});
{
"name": "memoizerific",
"version": "1.8.4",
"description": "Fast, small, most-efficient JavaScript memoization lib to memoize JS functions",
"author": "@thinkloop",
"version": "1.8.6",
"description": "Fast, small, efficient JavaScript memoization lib to memoize JS functions",
"author": "Baz <baz@thinkloop.com>",
"license": "MIT",
"keywords": [
"memoize",
"memoizer",
"memoization",
"memoized",
"javascript",
"js",
"lru",
"cache",
"fast"
],
"homepage": "https://github.com/thinkloop/memoizerific#readme",

@@ -15,38 +26,27 @@ "repository": {

},
"main": "src/memoizerific",
"main": "./memoizerific",
"scripts": {
"test": "npm run -s test:map && npm run -s test:similar",
"test": "echo '****************'`date +%r`'********************' && npm run -s test:map && npm run -s test:similar",
"build": "npm run -s build:all",
"publish_to_npm": "npm run -s build:all && git add --all && git commit -m \"build for publish\" && npm version patch && git push && git push --tags && npm publish",
"_": "",
"test:map": "TEST_MAPORSIMILAR=false JASMINE_CONFIG_PATH=./jasmine.json jasmine",
"test:similar": "TEST_MAPORSIMILAR=true JASMINE_CONFIG_PATH=./jasmine.json jasmine",
"test:map": "FORCE_SIMILAR_INSTEAD_OF_MAP=false JASMINE_CONFIG_PATH=./jasmine.json jasmine",
"test:similar": "FORCE_SIMILAR_INSTEAD_OF_MAP=true JASMINE_CONFIG_PATH=./jasmine.json jasmine",
"__": "",
"prebuild:all": "npm run -s test",
"build:all": "npm run -s build:browserify | tee memoizerific.js | npm run -s build:minify | tee memoizerific.min.js | npm run -s build:gzip > memoizerific.min.gzip.js",
"build:browserify": "browserify src/memoizerific.js --detectGlobals false --standalone memoizerific | derequire",
"build:browserify": "browserify src/memoizerific.js -t [envify purge] --detectGlobals false --standalone memoizerific | derequire",
"build:minify": "uglifyjs --compress drop_console,unused=false --mangle --screw-ie8",
"build:gzip": "gzip --best -v -c"
},
"keywords": [
"memoize",
"memoizer",
"memoization",
"memoized",
"javascript",
"js",
"lru",
"cache",
"fast"
],
"dependencies": {
"map-or-similar": "^1.2.3"
"map-or-similar": "^1.3.0"
},
"devDependencies": {
"browserify": "^13.0.1",
"derequire": "^2.0.3",
"jasmine": "^2.4.1",
"npm-check-updates": "^2.6.7",
"uglify-js": "^2.6.2",
"watch": "^0.18.0"
"browserify": "13.1.1",
"derequire": "2.0.3",
"envify": "4.0.0",
"jasmine": "2.5.2",
"uglify-js": "2.7.5",
"watch": "1.0.1"
}
}

@@ -5,9 +5,12 @@ # Memoizerific.js

Fast (see benchmarks), small (1k min/gzip), efficient, JavaScript memoization lib to memoize JS functions.
Fully supports multiple complex object arguments.
Implements LRU caching (least recently used caching) to maintain only the most recent results.
Made for the browser and nodejs. Uses JavaScript [Map()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) for instant object lookups, or a [performant polyfill](https://github.com/thinkloop/map-or-similar) if Map is not available - does not do serialization or string manipulation.
Uses JavaScript's new [Map()](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Map) object for instant lookups, or a [performant polyfill](https://github.com/thinkloop/map-or-similar) if Map is not available - does not do expensive serialization or string manipulation.
Fully supports multiple complex arguments.
Implements least recently used (LRU) caching to maintain only the most recent results.
Made for the browser and nodejs.
Memoization is the process of caching function results, so that they can be returned cheaply
without re-running the function when it is called again with the same arguments.
without re-execution, if the function is called again with the same arguments.
This is especially useful with the rise of [redux-philosophy](https://github.com/rackt/redux),

@@ -17,2 +20,4 @@ and the push to calculate derived data on the fly to maintain minimal state.

## Install
Add to your project directly from npm:
```

@@ -22,3 +27,3 @@ npm install memoizerific --save

Or use one of the compiled distributions compatible in any environment (umd):
Or use one of the compiled distributions compatible in any environment (UMD):

@@ -63,5 +68,5 @@ - [memoizerific.js](https://raw.githubusercontent.com/thinkloop/memoizerific/master/memoizerific.js)

memoizerific(1)(function(){}); // memoize 1 result
memoizerific(10000)(function(){}); // memoize 10,000 results
memoizerific(0)(function(){}); // memoize infinity results (not recommended)
memoizerific(1)(function(arg1){}); // memoize the last result
memoizerific(10000)(function(arg1, arg2){}); // memoize the last 10,000 unique argument combinations
memoizerific(0)(function(arg1){}); // memoize infinity results (not recommended)
```

@@ -175,14 +180,11 @@ The cache works using LRU logic, purging the least recently used results when the limit is reached.

The results from the tests are interesting.
While LRU-Memoize performed quite well with few arguments and lots of cache hits, it quickly started to fall apart as the environment became more challenging.
At 4+ arguments, it was 5x-10x-20x slower than the other contenders, and began to hit severe performance issues that could potentially cause real-world problems.
I would not recommend it for heavy production use.
While LRU-Memoize performed well with few arguments and lots of cache hits, it quickly degraded as the environment became more challenging. At 4+ arguments, it was 5x-10x-20x slower than the other contenders, and began to hit severe performance issues that could potentially cause real-world problems. I would not recommend it for heavy production use.
Memoizee came in a solid second place, around 31% less performant than Memoizerific.
In most scenarios this will not be very noticeable. In other, especially demanding ones,
such as memoizing in a loop, or through a long recursion chain, it might be.
Importantly though, it degraded very gracefully, and remained within sub 1s levels almost all the time.
Memoizee is a sturdy, well-built library that I would recommend for production use.
In most scenarios this will not be very noticeable, in others, like memoizing in a loop,
or recursively, it might be. Importantly though, it degraded gracefully, and remained within
sub 1s levels almost all the time. Memoizee is acceptable for production use.
Memoizerific was the performance winner. It is built with complex real-world use in mind.
I would, of course, recommend it for serious production use.
Memoizerific was the top winner. It was fastest in all tests except one. It was built with
complex real-world use in mind, and I would recommend it for production.

@@ -193,5 +195,12 @@ ## License

### Other Libs
## Related
- [Map or Similar](https://github.com/thinkloop/map-or-similar): A JavaScript (JS) Map or Similar object polyfill if Map is not available.
- [Multi Key Cache](https://github.com/thinkloop/multi-key-cache): A JavaScript (JS) cache that can have multiple complex values as keys.
## Other
- [todo-app](https://github.com/thinkloop/todo-app/): Example todo app of extreme decoupling of react, redux and selectors
- [link-react](https://github.com/thinkloop/link-react/): A generalized link <a> component that allows client-side navigation while taking into account exceptions
- [spa-webserver](https://github.com/thinkloop/spa-webserver/): Webserver that redirects to root index.html if path is missing for client-side SPA navigation
Like it? Star It
var MapOrSimilar = require('map-or-similar');
module.exports = function (limit) {
var cache = new MapOrSimilar(),
var cache = new MapOrSimilar(process.env.FORCE_SIMILAR_INSTEAD_OF_MAP === 'true'),
lru = [];

@@ -29,3 +29,3 @@

// climb through the hierarchical map tree until the second-last argument has been found, or an argument is missing.
// if all arguments up to the second-last have been found, this will potentially be a cache hit (determined below)
// if all arguments up to the second-last have been found, this will potentially be a cache hit (determined later)
if (currentCache.has(arguments[i])) {

@@ -39,3 +39,3 @@ currentCache = currentCache.get(arguments[i]);

// make maps until last value
newMap = new MapOrSimilar();
newMap = new MapOrSimilar(process.env.FORCE_SIMILAR_INSTEAD_OF_MAP === 'true');
currentCache.set(arguments[i], newMap);

@@ -42,0 +42,0 @@ currentCache = newMap;

@@ -16,3 +16,6 @@ var Memoizerific = require('../src/memoizerific');

it("should be map or similar", () => { expect(memoizedFn.cache instanceof Map).toEqual(process.env.TEST_MAPORSIMILAR !== 'true'); });
it("should be map or similar", () => {
console.log('FORCE_SIMILAR_INSTEAD_OF_MAP:', process.env.FORCE_SIMILAR_INSTEAD_OF_MAP);
expect(memoizedFn.cache instanceof Map).toEqual(process.env.FORCE_SIMILAR_INSTEAD_OF_MAP !== 'true');
});

@@ -19,0 +22,0 @@ it("should not be memoized", () => {

@@ -40,3 +40,3 @@ var Memoizerific = require('../src/memoizerific');

it("should be map or similar", () => { expect(fibonacciMemoized.cache instanceof Map).toEqual(process.env.TEST_MAPORSIMILAR !== 'true'); });
it("should be map or similar", () => { expect(fibonacciMemoized.cache instanceof Map).toEqual(process.env.FORCE_SIMILAR_INSTEAD_OF_MAP !== 'true'); });
it("should equal non-memoized result", () => { expect(fibonacciResult).toEqual(fibonacciMemoizedResult); });

@@ -43,0 +43,0 @@ it("should have proper lru length", () => { expect(fibonacciMemoized.lru.length).toEqual(41); });

@@ -17,3 +17,3 @@ var Memoizerific = require('../src/memoizerific');

it("should be map or similar", () => { expect(memoizedFn.cache instanceof Map).toEqual(process.env.TEST_MAPORSIMILAR !== 'true'); });
it("should be map or similar", () => { expect(memoizedFn.cache instanceof Map).toEqual(process.env.FORCE_SIMILAR_INSTEAD_OF_MAP !== 'true'); });

@@ -20,0 +20,0 @@ it("should be memoized", () => {

@@ -16,3 +16,3 @@ var Memoizerific = require('../src/memoizerific');

it("should be map or similar", () => { expect(memoizedFn.cache instanceof Map).toEqual(process.env.TEST_MAPORSIMILAR !== 'true'); });
it("should be map or similar", () => { expect(memoizedFn.cache instanceof Map).toEqual(process.env.FORCE_SIMILAR_INSTEAD_OF_MAP !== 'true'); });

@@ -19,0 +19,0 @@ it("should not be memoized", () => {

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