-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathlru-cache.js
10 lines (10 loc) · 10.3 KB
/
lru-cache.js
1
2
3
4
5
6
7
8
9
10
const exports = {};
const module = {exports};
var parcelRequire=function(e,r,t,n){var i,o="function"==typeof parcelRequire&&parcelRequire,u="function"==typeof require&&require;function f(t,n){if(!r[t]){if(!e[t]){var i="function"==typeof parcelRequire&&parcelRequire;if(!n&&i)return i(t,!0);if(o)return o(t,!0);if(u&&"string"==typeof t)return u(t);var c=new Error("Cannot find module '"+t+"'");throw c.code="MODULE_NOT_FOUND",c}p.resolve=function(r){return e[t][1][r]||r},p.cache={};var l=r[t]=new f.Module(t);e[t][0].call(l.exports,p,l,l.exports,this)}return r[t].exports;function p(e){return f(p.resolve(e))}}f.isParcelRequire=!0,f.Module=function(e){this.id=e,this.bundle=f,this.exports={}},f.modules=e,f.cache=r,f.parent=o,f.register=function(r,t){e[r]=[function(e,r){r.exports=t},{}]};for(var c=0;c<t.length;c++)try{f(t[c])}catch(e){i||(i=e)}if(t.length){var l=f(t[t.length-1]);"object"==typeof exports&&"undefined"!=typeof module?module.exports=l:"function"==typeof define&&define.amd?define(function(){return l}):n&&(this[n]=l)}if(parcelRequire=f,i)throw i;return f}({"H3eE":[function(require,module,exports) {
"use strict";module.exports=function(t){t.prototype[Symbol.iterator]=function*(){for(let t=this.head;t;t=t.next)yield t.value}};
},{}],"wXzr":[function(require,module,exports) {
"use strict";function t(e){var i=this;if(i instanceof t||(i=new t),i.tail=null,i.head=null,i.length=0,e&&"function"==typeof e.forEach)e.forEach(function(t){i.push(t)});else if(arguments.length>0)for(var n=0,h=arguments.length;n<h;n++)i.push(arguments[n]);return i}function e(t,e,i){var n=e===t.head?new h(i,null,e,t):new h(i,e,e.next,t);return null===n.next&&(t.tail=n),null===n.prev&&(t.head=n),t.length++,n}function i(t,e){t.tail=new h(e,t.tail,null,t),t.head||(t.head=t.tail),t.length++}function n(t,e){t.head=new h(e,null,t.head,t),t.tail||(t.tail=t.head),t.length++}function h(t,e,i,n){if(!(this instanceof h))return new h(t,e,i,n);this.list=n,this.value=t,e?(e.next=this,this.prev=e):this.prev=null,i?(i.prev=this,this.next=i):this.next=null}module.exports=t,t.Node=h,t.create=t,t.prototype.removeNode=function(t){if(t.list!==this)throw new Error("removing node which does not belong to this list");var e=t.next,i=t.prev;return e&&(e.prev=i),i&&(i.next=e),t===this.head&&(this.head=e),t===this.tail&&(this.tail=i),t.list.length--,t.next=null,t.prev=null,t.list=null,e},t.prototype.unshiftNode=function(t){if(t!==this.head){t.list&&t.list.removeNode(t);var e=this.head;t.list=this,t.next=e,e&&(e.prev=t),this.head=t,this.tail||(this.tail=t),this.length++}},t.prototype.pushNode=function(t){if(t!==this.tail){t.list&&t.list.removeNode(t);var e=this.tail;t.list=this,t.prev=e,e&&(e.next=t),this.tail=t,this.head||(this.head=t),this.length++}},t.prototype.push=function(){for(var t=0,e=arguments.length;t<e;t++)i(this,arguments[t]);return this.length},t.prototype.unshift=function(){for(var t=0,e=arguments.length;t<e;t++)n(this,arguments[t]);return this.length},t.prototype.pop=function(){if(this.tail){var t=this.tail.value;return this.tail=this.tail.prev,this.tail?this.tail.next=null:this.head=null,this.length--,t}},t.prototype.shift=function(){if(this.head){var t=this.head.value;return this.head=this.head.next,this.head?this.head.prev=null:this.tail=null,this.length--,t}},t.prototype.forEach=function(t,e){e=e||this;for(var i=this.head,n=0;null!==i;n++)t.call(e,i.value,n,this),i=i.next},t.prototype.forEachReverse=function(t,e){e=e||this;for(var i=this.tail,n=this.length-1;null!==i;n--)t.call(e,i.value,n,this),i=i.prev},t.prototype.get=function(t){for(var e=0,i=this.head;null!==i&&e<t;e++)i=i.next;if(e===t&&null!==i)return i.value},t.prototype.getReverse=function(t){for(var e=0,i=this.tail;null!==i&&e<t;e++)i=i.prev;if(e===t&&null!==i)return i.value},t.prototype.map=function(e,i){i=i||this;for(var n=new t,h=this.head;null!==h;)n.push(e.call(i,h.value,this)),h=h.next;return n},t.prototype.mapReverse=function(e,i){i=i||this;for(var n=new t,h=this.tail;null!==h;)n.push(e.call(i,h.value,this)),h=h.prev;return n},t.prototype.reduce=function(t,e){var i,n=this.head;if(arguments.length>1)i=e;else{if(!this.head)throw new TypeError("Reduce of empty list with no initial value");n=this.head.next,i=this.head.value}for(var h=0;null!==n;h++)i=t(i,n.value,h),n=n.next;return i},t.prototype.reduceReverse=function(t,e){var i,n=this.tail;if(arguments.length>1)i=e;else{if(!this.tail)throw new TypeError("Reduce of empty list with no initial value");n=this.tail.prev,i=this.tail.value}for(var h=this.length-1;null!==n;h--)i=t(i,n.value,h),n=n.prev;return i},t.prototype.toArray=function(){for(var t=new Array(this.length),e=0,i=this.head;null!==i;e++)t[e]=i.value,i=i.next;return t},t.prototype.toArrayReverse=function(){for(var t=new Array(this.length),e=0,i=this.tail;null!==i;e++)t[e]=i.value,i=i.prev;return t},t.prototype.slice=function(e,i){(i=i||this.length)<0&&(i+=this.length),(e=e||0)<0&&(e+=this.length);var n=new t;if(i<e||i<0)return n;e<0&&(e=0),i>this.length&&(i=this.length);for(var h=0,l=this.head;null!==l&&h<e;h++)l=l.next;for(;null!==l&&h<i;h++,l=l.next)n.push(l.value);return n},t.prototype.sliceReverse=function(e,i){(i=i||this.length)<0&&(i+=this.length),(e=e||0)<0&&(e+=this.length);var n=new t;if(i<e||i<0)return n;e<0&&(e=0),i>this.length&&(i=this.length);for(var h=this.length,l=this.tail;null!==l&&h>i;h--)l=l.prev;for(;null!==l&&h>e;h--,l=l.prev)n.push(l.value);return n},t.prototype.splice=function(t,i,...n){t>this.length&&(t=this.length-1),t<0&&(t=this.length+t);for(var h=0,l=this.head;null!==l&&h<t;h++)l=l.next;var r=[];for(h=0;l&&h<i;h++)r.push(l.value),l=this.removeNode(l);null===l&&(l=this.tail),l!==this.head&&l!==this.tail&&(l=l.prev);for(h=0;h<n.length;h++)l=e(this,l,n[h]);return r},t.prototype.reverse=function(){for(var t=this.head,e=this.tail,i=t;null!==i;i=i.prev){var n=i.prev;i.prev=i.next,i.next=n}return this.head=e,this.tail=t,this};try{require("./iterator.js")(t)}catch(l){}
},{"./iterator.js":"H3eE"}],"Focm":[function(require,module,exports) {
"use strict";function t(t,e){if(!(t instanceof e))throw new TypeError("Cannot call a class as a function")}function e(t,e){for(var n=0;n<e.length;n++){var i=e[n];i.enumerable=i.enumerable||!1,i.configurable=!0,"value"in i&&(i.writable=!0),Object.defineProperty(t,i.key,i)}}function n(t,n,i){return n&&e(t.prototype,n),i&&e(t,i),t}var i=require("yallist"),r=Symbol("max"),u=Symbol("length"),a=Symbol("lengthCalculator"),s=Symbol("allowStale"),o=Symbol("maxAge"),h=Symbol("dispose"),l=Symbol("noDisposeOnSet"),f=Symbol("lruList"),v=Symbol("cache"),c=Symbol("updateAgeOnGet"),y=function(){return 1},m=function(){function e(n){if(t(this,e),"number"==typeof n&&(n={max:n}),n||(n={}),n.max&&("number"!=typeof n.max||n.max<0))throw new TypeError("max must be a non-negative number");this[r]=n.max||1/0;var i=n.length||y;if(this[a]="function"!=typeof i?y:i,this[s]=n.stale||!1,n.maxAge&&"number"!=typeof n.maxAge)throw new TypeError("maxAge must be a number");this[o]=n.maxAge||0,this[h]=n.dispose,this[l]=n.noDisposeOnSet||!1,this[c]=n.updateAgeOnGet||!1,this.reset()}return n(e,[{key:"rforEach",value:function(t,e){e=e||this;for(var n=this[f].tail;null!==n;){var i=n.prev;x(this,t,n,e),n=i}}},{key:"forEach",value:function(t,e){e=e||this;for(var n=this[f].head;null!==n;){var i=n.next;x(this,t,n,e),n=i}}},{key:"keys",value:function(){return this[f].toArray().map(function(t){return t.key})}},{key:"values",value:function(){return this[f].toArray().map(function(t){return t.value})}},{key:"reset",value:function(){var t=this;this[h]&&this[f]&&this[f].length&&this[f].forEach(function(e){return t[h](e.key,e.value)}),this[v]=new Map,this[f]=new i,this[u]=0}},{key:"dump",value:function(){var t=this;return this[f].map(function(e){return!p(t,e)&&{k:e.key,v:e.value,e:e.now+(e.maxAge||0)}}).toArray().filter(function(t){return t})}},{key:"dumpLru",value:function(){return this[f]}},{key:"set",value:function(t,e,n){if((n=n||this[o])&&"number"!=typeof n)throw new TypeError("maxAge must be a number");var i=n?Date.now():0,s=this[a](e,t);if(this[v].has(t)){if(s>this[r])return b(this,this[v].get(t)),!1;var c=this[v].get(t).value;return this[h]&&(this[l]||this[h](t,c.value)),c.now=i,c.maxAge=n,c.value=e,this[u]+=s-c.length,c.length=s,this.get(t),k(this),!0}var y=new w(t,e,s,i,n);return y.length>this[r]?(this[h]&&this[h](t,e),!1):(this[u]+=y.length,this[f].unshift(y),this[v].set(t,this[f].head),k(this),!0)}},{key:"has",value:function(t){if(!this[v].has(t))return!1;var e=this[v].get(t).value;return!p(this,e)}},{key:"get",value:function(t){return g(this,t,!0)}},{key:"peek",value:function(t){return g(this,t,!1)}},{key:"pop",value:function(){var t=this[f].tail;return t?(b(this,t),t.value):null}},{key:"del",value:function(t){b(this,this[v].get(t))}},{key:"load",value:function(t){this.reset();for(var e=Date.now(),n=t.length-1;n>=0;n--){var i=t[n],r=i.e||0;if(0===r)this.set(i.k,i.v);else{var u=r-e;u>0&&this.set(i.k,i.v,u)}}}},{key:"prune",value:function(){var t=this;this[v].forEach(function(e,n){return g(t,n,!1)})}},{key:"max",set:function(t){if("number"!=typeof t||t<0)throw new TypeError("max must be a non-negative number");this[r]=t||1/0,k(this)},get:function(){return this[r]}},{key:"allowStale",set:function(t){this[s]=!!t},get:function(){return this[s]}},{key:"maxAge",set:function(t){if("number"!=typeof t)throw new TypeError("maxAge must be a non-negative number");this[o]=t,k(this)},get:function(){return this[o]}},{key:"lengthCalculator",set:function(t){var e=this;"function"!=typeof t&&(t=y),t!==this[a]&&(this[a]=t,this[u]=0,this[f].forEach(function(t){t.length=e[a](t.value,t.key),e[u]+=t.length})),k(this)},get:function(){return this[a]}},{key:"length",get:function(){return this[u]}},{key:"itemCount",get:function(){return this[f].length}}]),e}(),g=function(t,e,n){var i=t[v].get(e);if(i){var r=i.value;if(p(t,r)){if(b(t,i),!t[s])return}else n&&(t[c]&&(i.value.now=Date.now()),t[f].unshiftNode(i));return r.value}},p=function(t,e){if(!e||!e.maxAge&&!t[o])return!1;var n=Date.now()-e.now;return e.maxAge?n>e.maxAge:t[o]&&n>t[o]},k=function(t){if(t[u]>t[r])for(var e=t[f].tail;t[u]>t[r]&&null!==e;){var n=e.prev;b(t,e),e=n}},b=function(t,e){if(e){var n=e.value;t[h]&&t[h](n.key,n.value),t[u]-=n.length,t[v].delete(n.key),t[f].removeNode(e)}},w=function e(n,i,r,u,a){t(this,e),this.key=n,this.value=i,this.length=r,this.now=u,this.maxAge=a||0},x=function(t,e,n,i){var r=n.value;p(t,r)&&(b(t,n),t[s]||(r=void 0)),r&&e.call(i,r.value,r.key,t)};module.exports=m;
},{"yallist":"wXzr"}]},{},["Focm"], null)
export default module.exports;