🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
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

to
1.3.0

jasmine.json

115

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') {
module.exports = Map;
if (typeof Map !== 'function' || (process && process.env && process.env.TEST_MAPORSIMILAR === 'true')) {
module.exports = _dereq_('./similar');
}
else {
module.exports = Similar;
module.exports = Map;
}
},{"./similar":2}],2:[function(_dereq_,module,exports){
function Similar() {
this.list = [];
this.lastHas = null;
this.lastItem = undefined;
this.size = 0;
return this;

@@ -18,22 +18,36 @@ }

Similar.prototype.get = function(key) {
var len = this.list.length,
i;
if (this.lastGet && this.lastGet.key === key) {
return this.lastGet.val;
var index;
if (this.lastItem && this.lastItem.key === key) {
return this.lastItem.val;
}
for (i = 0; i < len; i++) {
if (this.list[i].key === key) {
this.lastGet = this.list[i];
return this.list[i];
}
index = this.indexOf(key);
if (index >= 0) {
this.lastItem = this.list[index];
return this.list[index].val;
}
return null;
return undefined;
};
Similar.prototype.set = function(key, val) {
this.list.push({ key: key, val: val });
var index;
if (this.lastItem && 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;

@@ -43,21 +57,49 @@ };

Similar.prototype.delete = function(key) {
var len = this.list.length,
i;
for (i = 0; i < len; i++) {
if (this.list[i].key === key) {
break;
}
var index;
if (this.lastItem && this.lastItem.key === key) {
this.lastItem = undefined;
}
if (this.list.splice(i, 1).length) {
index = this.indexOf(key);
if (index >= 0) {
this.size--;
return this.list.splice(index, 1)[0];
}
return this;
return undefined;
};
Similar.prototype.has = Similar.prototype.get;
},{}],2:[function(_dereq_,module,exports){
var MapOrSimilar = _dereq_('./maporsimilar');
// 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.lastItem.key === key) {
return true;
}
index = this.indexOf(key);
if (index >= 0) {
this.lastItem = this.list[index];
return true;
}
return false;
};
Similar.prototype.indexOf = function(key) {
var i;
for (i = 0; i < this.size; i++) {
if (this.list[i].key === key) {
return i;
}
}
return -1;
};
module.exports = Similar;
},{}],3:[function(_dereq_,module,exports){
var MapOrSimilar = _dereq_('map-or-similar');
module.exports = function (limit) {

@@ -125,5 +167,10 @@ var cache = new MapOrSimilar(),

memoizerific.wasMemoized = isMemoized;
return fnResult;
};
memoizerific.cache = cache;
memoizerific.lru = lru;
return memoizerific;

@@ -178,3 +225,3 @@ };

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

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

��Uێ�6�[
Ӫ��Ri�h� �d_�'A�2�bC�*Ee����;��kc�� ��9s�hTn�V��V(��������b�����u�:�B(~
��dz>5��� ��"�pY���g�% �g��'�Q��_m�1�� ���> u�O����x����c���QsY�OlKQ��Y��܈B䞁sh����ƨ�hYYĉ!
��E MX'�ڤ:�O�;y. �����6€�!�wX6x���z���m�`�U�i��mP�+SJ�= �Y� 6z� pbK��VE��������>|�t�����?z��y<I}�*��%�C�ˢ�I��Xd�����q��6K�T2G[�$�MKz����C�]L<\�#zMw��YE��G[&z��)/���C�>N�l}�E����IQ[���{a����T5R��Z����GV�9��x~SDE��V{��[�ZBȌNI����S.�s�˷�+�_P�}c2�rB‰9�0yuF4�����t�H�/��^w���`E���Q��%j!nl ds�gi7�^�%h���ُ ��<�5�]�N��*���"�0�{<@ �}b��ubQ�[㲦��.#wo6\�K72DA`_�����A%
�m�������������R�E�<9>Ax��'���� �[la��[�Y\����H�}�e&`�%����\���P����. ��f2���jt^�5�4��l��-h�o���3����YHf`��sv�$ݎ�!�t���G�>�.v}g )����"7g�l=H�ݓ��b {F�f�IU�T)�2�H
�L��G'*�$OP���� ��ᣤ����#��'l`"��]x�?$˦��A���%�7W�`�=8�xyA ��*����7�᫘eF �{�E���-�%�͏
R���-XA� �`��_ET���^�m�Ȅ93�����e~�Hz�at�N���+�
�p��Vmemoizerific.min.js�V[o�6~߯����0��ɛT�� �4C�>B��Tĕ�4�J����;�͖���bQG������T��BoE����O[�R�Z�<��E���L�Rmx"�x��c�oJ�q��[Uj�4|��:�=b�2�4O�e��:"���}fz�CN�Y}j����GpN�I�L���Y �e�r?�M�!��x��\�D�΃�B}hpM�ND��-�u�F����%1����5���O��gb��_�����;�dR��^ ��9vr��T+s� U�et�u���S*�#pyӦh�Λ����áMu�2J�8�@xo�>|�x����������>x$����;ݶ9 �U:��ȏ��Hv�&��
Z+.����pi$V"��"��o���U��3�}�����/��<d�/�z�iȦS��qA�)Th��{��8����ڸe�nW�<��=�\=CX]r�A�������۫?�>����x�yu� �����L{8�#�| .��\����@������0����_��7�g�9�Ѽ(hڜ+�e�;�'n�q�x8�n�&��������v5�>C�!Nk!��~�,�K:_�!����w̛���=��!]3�Kx[f��0:aLymH�0o2��E4^ڂ�� ^�o�Eiҡ*ާl:m��°�[�s��Lйr�\��=Gj6;�o
)b�o�a ti�M���"��WU�H Ƌ��g�9]����!�ä�g˪��+�EE�]m����/�l�} S�,b((�jZ
h��
��:���y=�̒�3Α\���M��ƴ��������[Z7Ǯ���6�����B�gD�|���!�f&` �)����%��Y�)�]�����i�E�a�t�c�ۍ��Ü���?�V�*�q��b��Y?S�}�O�[/E�����F����њ/��XS)�eƕ���lA2z�5{E�t�I�Q��( '� �I�.`q�~%����)]{�C^���c3��,H�zR�a8� &%M�5C؏�S@�'� 88��!I�ϊB�"UJIz5|b3���0��.����l
��+��p ��Y'ڐ.a"�j2�H�O��� 3�͟� ���:��6 =�/uIɫ��У�U�ڐ�/#�.q��_��Fq�

@@ -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(){return function t(e,r,n){function i(o,a){if(!r[o]){if(!e[o]){var u="function"==typeof require&&require;if(!a&&u)return u(o,!0);if(s)return s(o,!0);var f=new Error("Cannot find module '"+o+"'");throw f.code="MODULE_NOT_FOUND",f}var l=r[o]={exports:{}};e[o][0].call(l.exports,function(t){var r=e[o][1][t];return i(r?r:t)},l,l.exports,t,e,r,n)}return r[o].exports}for(var s="function"==typeof require&&require,o=0;o<n.length;o++)i(n[o]);return i}({1:[function(t,e,r){function n(){return this.list=[],this.lastHas=null,this.size=0,this}"function"==typeof Map?e.exports=Map:e.exports=n,n.prototype.get=function(t){var e,r=this.list.length;if(this.lastGet&&this.lastGet.key===t)return this.lastGet.val;for(e=0;r>e;e++)if(this.list[e].key===t)return this.lastGet=this.list[e],this.list[e];return null},n.prototype.set=function(t,e){return this.list.push({key:t,val:e}),this.size++,this},n.prototype["delete"]=function(t){var e,r=this.list.length;for(e=0;r>e&&this.list[e].key!==t;e++);return this.list.splice(e,1).length&&this.size--,this},n.prototype.has=n.prototype.get},{}],2:[function(t,e,r){function n(t,e){var r,n,i,s=t.length,o=e.length;for(n=0;s>n;n++){for(r=!0,i=0;o>i;i++)if(t[n][i].arg!==e[i].arg){r=!1;break}if(r)break}t.push(t.splice(n,1)[0])}function i(t){var e,r,n=t.length,i=t[n-1];for(i.cacheItem["delete"](i.arg),r=n-2;r>=0&&(i=t[r],e=i.cacheItem.get(i.arg),!e||!e.size);r--)i.cacheItem["delete"](i.arg)}var s=t("./maporsimilar");e.exports=function(t){var e=new s,r=[];return function(o){var a=function(){var a,u,f,l=e,h=arguments.length-1,p=Array(h+1),c=!0;for(f=0;h>f;f++)p[f]={cacheItem:l,arg:arguments[f]},l.has(arguments[f])?l=l.get(arguments[f]):(c=!1,a=new s,l.set(arguments[f],a),l=a);return c&&(l.has(arguments[h])?u=l.get(arguments[h]):c=!1),c||(u=o.apply(null,arguments),l.set(arguments[h],u)),t>0&&(p[h]={cacheItem:l,arg:arguments[h]},c?n(r,p):r.push(p),r.length>t&&i(r.shift())),u};return a}}},{"./maporsimilar":1}]},{},[2])(2)});
!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(a,o){if(!i[a]){if(!e[a]){var u="function"==typeof require&&require;if(!o&&u)return u(a,!0);if(n)return n(a,!0);var f=new Error("Cannot find module '"+a+"'");throw f.code="MODULE_NOT_FOUND",f}var l=i[a]={exports:{}};e[a][0].call(l.exports,function(t){var i=e[a][1][t];return r(i?i:t)},l,l.exports,t,e,i,s)}return i[a].exports}for(var n="function"==typeof require&&require,a=0;a<s.length;a++)r(s[a]);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.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.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.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.lastItem.key===t?!0:(e=this.indexOf(t),e>=0?(this.lastItem=this.list[e],!0):!1)},s.prototype.indexOf=function(t){var e;for(e=0;e<this.size;e++)if(this.list[e].key===t)return e;return-1},e.exports=s},{}],3:[function(t,e,i){function s(t,e){var i=t.length,s=e.length,r,n,a;for(n=0;i>n;n++){for(r=!0,a=0;s>a;a++)if(t[n][a].arg!==e[a].arg){r=!1;break}if(r)break}t.push(t.splice(n,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)}var n=t("map-or-similar");e.exports=function(t){var e=new n,i=[];return function(a){var o=function(){var u=e,f,l,h=arguments.length-1,m=Array(h+1),c=!0,p;for(p=0;h>p;p++)m[p]={cacheItem:u,arg:arguments[p]},u.has(arguments[p])?u=u.get(arguments[p]):(c=!1,f=new n,u.set(arguments[p],f),u=f);return c&&(u.has(arguments[h])?l=u.get(arguments[h]):c=!1),c||(l=a.apply(null,arguments),u.set(arguments[h],l)),t>0&&(m[h]={cacheItem:u,arg:arguments[h]},c?s(i,m):i.push(m),i.length>t&&r(i.shift())),o.wasMemoized=c,l};return o.cache=e,o.lru=i,o}}},{"map-or-similar":1}]},{},[3])(3)});
{
"name": "memoizerific",
"version": "1.2.2",
"version": "1.3.0",
"description": "Fastest, smallest, most-efficient JavaScript memoization lib to memoize JS functions",

@@ -15,5 +15,13 @@ "author": "@thinkloop",

},
"main": "memoizerific.min",
"main": "src/memoizerific",
"scripts": {
"test": "echo \"Error: no test specified\" && exit 1"
"prebuild": "npm run test",
"build": "npm run build:browserify && npm run build:minify && npm run build:gzip",
"build:browserify": "browserify src/memoizerific.js --detectGlobals false --standalone memoizerific | derequire > memoizerific.js",
"build:minify": "uglifyjs memoizerific.js --compress drop_console,unused=false --mangle --screw-ie8 > memoizerific.min.js",
"build:gzip": "gzip --best -v -c memoizerific.min.js > memoizerific.min.gzip.js",
"build:stream": "browserify src/memoizerific.js --standalone memoizerific | derequire | tee dist/memoizerific.js | uglifyjs --compress drop_console,unused=false --mangle --screw-ie8 | tee dist/memoizerific.min.js | gzip --best -v -c > dist/memoizerific.min.gzip.js",
"test": "npm run test:map && npm run test:similar",
"test:map": "TEST_MAPORSIMILAR=false JASMINE_CONFIG_PATH=jasmine.json jasmine",
"test:similar": "TEST_MAPORSIMILAR=true JASMINE_CONFIG_PATH=jasmine.json jasmine"
},

@@ -30,16 +38,11 @@ "keywords": [

],
"dependencies": {},
"dependencies": {
"map-or-similar": "^1.0.6"
},
"devDependencies": {
"browserify": "^13.0.0",
"gulp": "^3.9.0",
"gulp-derequire": "^2.1.0",
"gulp-gzip": "^1.2.0",
"gulp-rename": "^1.2.2",
"gulp-streamify": "^1.0.2",
"gulp-uglify": "^1.5.1",
"gulp-util": "^3.0.7",
"run-sequence": "^1.1.5",
"vinyl-buffer": "^1.0.0",
"vinyl-source-stream": "^1.1.0"
"derequire": "^2.0.3",
"jasmine": "^2.4.1",
"uglify-js": "^2.6.1"
}
}
# Memoizerific.js
Fastest (see benchmarks), smallest (923b min/gzip), most-efficient, dependency-free, JavaScript memoization lib to memoize JS functions.
Fully supports multiple complex object arguments.
Implements LRU (least recently used) cache to maintain only the most recent results.
Fastest (see benchmarks), smallest (1k min/gzip), most-efficient, JavaScript memoization lib to memoize JS functions.
Fully supports multiple complex object arguments.
Implements LRU (least recently used) cache 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
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.

@@ -31,5 +31,5 @@

## Options
There is one option available:
There is one option available:
`limit:` the max number of results to cache.
`limit:` the max number of results to cache.

@@ -59,3 +59,3 @@

## Comparison
There are many memoization libs available for JavaScript. Some of them have specialized use-cases, such as memoizing file-system access, or server async requests.
There are many memoization libs available for JavaScript. Some of them have specialized use-cases, such as memoizing file-system access, or server async requests.
While others, such as this one, tackle the more general case of memoizing standard synchronous functions.

@@ -69,7 +69,7 @@ Following are the minimum criteria I look for in a production-worthy memoization solution:

Using this list, we can narrow down the field of possible candidates quite a bit.
The popular [lodash memoize](https://lodash.com/docs#memoize), for example, only supports one argument out of the box and has no cache control.
Using this list, we can narrow down the field of possible candidates quite a bit.
The popular [lodash memoize](https://lodash.com/docs#memoize), for example, only supports one argument out of the box and has no cache control.
Others support multiple complex arguments, but do not offer mechanisms to manage the cache-size:
- :heavy_multiplication_x: [Memoizejs](https://github.com/addyosmani/memoize.js) (@addyosmani)
- :heavy_multiplication_x: [Memoizejs](https://github.com/addyosmani/memoize.js) (@addyosmani)

@@ -94,4 +94,4 @@ - :heavy_multiplication_x: [Memoize-strict](https://github.com/jshanson7/memoize-strict) (@jshanson7)

This library is intended for real-world use-cases, and is therefore benchmarked against other libraries using large, complex, real-world data.
There are enough fibonacci solvers out there.
This library is intended for real-world use-cases, and is therefore benchmarked against other libraries using large, complex, real-world data.
There are enough fibonacci solvers out there.
Example arguments look like this:

@@ -108,3 +108,3 @@ ```javascript

We generated sets of thousands of random argument combinations of varying variance (to increase and decrease cache hits and misses) and fed
them to each library. For the full details and source of the benchmarks see [memoize-js-libs-benchmarks](https://github.com/thinkloop/memoize-js-libs-benchmarks).
them to each library.

@@ -135,5 +135,5 @@ ##### Data

The results from the tests are interesting.
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.
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.

@@ -147,3 +147,3 @@

Memoizerific was the performance winner. It is built with complex real-world use in mind.
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.

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

var MapOrSimilar = require('./maporsimilar');
var MapOrSimilar = require('map-or-similar');

@@ -65,5 +65,10 @@ module.exports = function (limit) {

memoizerific.wasMemoized = isMemoized;
return fnResult;
};
memoizerific.cache = cache;
memoizerific.lru = lru;
return memoizerific;

@@ -70,0 +75,0 @@ };

Sorry, the diff of this file is not supported yet