Socket
Socket
Sign inDemoInstall

tiny-lru

Package Overview
Dependencies
0
Maintainers
1
Versions
97
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

Comparing version 10.2.2 to 10.3.0

45

dist/tiny-lru.esm.js

@@ -6,3 +6,3 @@ /**

* @license BSD-3-Clause
* @version 10.2.2
* @version 10.3.0
*/

@@ -12,19 +12,13 @@ class LRU {

this.first = null;
this.items = Object.create(null);
this.items = new Map();
this.last = null;
this.max = max;
this.resetTtl = resetTtl;
this.size = 0;
this.ttl = ttl;
}
#has (key) {
return key in this.items;
}
clear () {
this.first = null;
this.items = Object.create(null);
this.items = new Map();
this.last = null;
this.size = 0;

@@ -35,7 +29,6 @@ return this;

delete (key) {
if (this.#has(key)) {
const item = this.items[key];
if (this.items.has(key)) {
const item = this.items.get(key);
delete this.items[key];
this.size--;
this.items.delete(key);

@@ -66,4 +59,3 @@ if (item.prev !== null) {

delete this.items[item.key];
this.size--;
this.items.delete(item.key);

@@ -85,4 +77,4 @@ if (this.size === 0) {

if (this.#has(key)) {
const item = this.items[key];
if (this.items.has(key)) {
const item = this.items.get(key);

@@ -103,4 +95,4 @@ if (this.ttl > 0 && item.expiry <= Date.now()) {

if (this.#has(key)) {
result = this.items[key].expiry;
if (this.items.has(key)) {
result = this.items.get(key).expiry;
}

@@ -112,3 +104,3 @@

keys () {
return Object.keys(this.items);
return this.items.keys();
}

@@ -119,4 +111,4 @@

if (bypass || this.#has(key)) {
item = this.items[key];
if (bypass || this.items.has(key)) {
item = this.items.get(key);
item.value = value;

@@ -154,3 +146,3 @@

item = this.items[key] = {
item = {
expiry: this.ttl > 0 ? Date.now() + this.ttl : this.ttl,

@@ -162,4 +154,5 @@ key: key,

};
this.items.set(key, item);
if (++this.size === 1) {
if (this.size === 1) {
this.first = item;

@@ -175,2 +168,6 @@ } else {

}
get size () {
return this.items.size;
}
}

@@ -177,0 +174,0 @@

/*!
2023 Jason Mulligan <jason.mulligan@avoidwork.com>
@version 10.2.2
@version 10.3.0
*/
class t{constructor(t=0,s=0,e=!1){this.first=null,this.items=Object.create(null),this.last=null,this.max=t,this.resetTtl=e,this.size=0,this.ttl=s}#t(t){return t in this.items}clear(){return this.first=null,this.items=Object.create(null),this.last=null,this.size=0,this}delete(t){if(this.#t(t)){const s=this.items[t];delete this.items[t],this.size--,null!==s.prev&&(s.prev.next=s.next),null!==s.next&&(s.next.prev=s.prev),this.first===s&&(this.first=s.next),this.last===s&&(this.last=s.prev)}return this}evict(t=!1){if(t||this.size>0){const t=this.first;delete this.items[t.key],this.size--,0===this.size?(this.first=null,this.last=null):(this.first=t.next,this.first.prev=null)}return this}get(t){let s;if(this.#t(t)){const e=this.items[t];this.ttl>0&&e.expiry<=Date.now()?this.delete(t):(s=e.value,this.set(t,s,!0))}return s}expiresAt(t){let s;return this.#t(t)&&(s=this.items[t].expiry),s}keys(){return Object.keys(this.items)}set(t,s,e=!1,i=this.resetTtl){let h;if(e||this.#t(t)){if(h=this.items[t],h.value=s,i&&(h.expiry=this.ttl>0?Date.now()+this.ttl:this.ttl),this.last!==h){const t=this.last,s=h.next,e=h.prev;this.first===h&&(this.first=h.next),h.next=null,h.prev=this.last,t.next=h,null!==e&&(e.next=s),null!==s&&(s.prev=e)}}else this.max>0&&this.size===this.max&&this.evict(!0),h=this.items[t]={expiry:this.ttl>0?Date.now()+this.ttl:this.ttl,key:t,prev:this.last,next:null,value:s},1==++this.size?this.first=h:this.last.next=h;return this.last=h,this}}function s(s=1e3,e=0,i=!1){if(isNaN(s)||s<0)throw new TypeError("Invalid max value");if(isNaN(e)||e<0)throw new TypeError("Invalid ttl value");if("boolean"!=typeof i)throw new TypeError("Invalid resetTtl value");return new t(s,e,i)}export{s as lru};//# sourceMappingURL=tiny-lru.esm.min.js.map
class t{constructor(t=0,s=0,e=!1){this.first=null,this.items=new Map,this.last=null,this.max=t,this.resetTtl=e,this.ttl=s}clear(){return this.first=null,this.items=new Map,this.last=null,this}delete(t){if(this.items.has(t)){const s=this.items.get(t);this.items.delete(t),null!==s.prev&&(s.prev.next=s.next),null!==s.next&&(s.next.prev=s.prev),this.first===s&&(this.first=s.next),this.last===s&&(this.last=s.prev)}return this}evict(t=!1){if(t||this.size>0){const t=this.first;this.items.delete(t.key),0===this.size?(this.first=null,this.last=null):(this.first=t.next,this.first.prev=null)}return this}get(t){let s;if(this.items.has(t)){const e=this.items.get(t);this.ttl>0&&e.expiry<=Date.now()?this.delete(t):(s=e.value,this.set(t,s,!0))}return s}expiresAt(t){let s;return this.items.has(t)&&(s=this.items.get(t).expiry),s}keys(){return this.items.keys()}set(t,s,e=!1,i=this.resetTtl){let l;if(e||this.items.has(t)){if(l=this.items.get(t),l.value=s,i&&(l.expiry=this.ttl>0?Date.now()+this.ttl:this.ttl),this.last!==l){const t=this.last,s=l.next,e=l.prev;this.first===l&&(this.first=l.next),l.next=null,l.prev=this.last,t.next=l,null!==e&&(e.next=s),null!==s&&(s.prev=e)}}else this.max>0&&this.size===this.max&&this.evict(!0),l={expiry:this.ttl>0?Date.now()+this.ttl:this.ttl,key:t,prev:this.last,next:null,value:s},this.items.set(t,l),1===this.size?this.first=l:this.last.next=l;return this.last=l,this}get size(){return this.items.size}}function s(s=1e3,e=0,i=!1){if(isNaN(s)||s<0)throw new TypeError("Invalid max value");if(isNaN(e)||e<0)throw new TypeError("Invalid ttl value");if("boolean"!=typeof i)throw new TypeError("Invalid resetTtl value");return new t(s,e,i)}export{s as lru};//# sourceMappingURL=tiny-lru.esm.min.js.map

@@ -6,3 +6,3 @@ /**

* @license BSD-3-Clause
* @version 10.2.2
* @version 10.3.0
*/

@@ -12,19 +12,13 @@ (function(g,f){typeof exports==='object'&&typeof module!=='undefined'?f(exports):typeof define==='function'&&define.amd?define(['exports'],f):(g=typeof globalThis!=='undefined'?globalThis:g||self,f(g.lru={}));})(this,(function(exports){'use strict';class LRU {

this.first = null;
this.items = Object.create(null);
this.items = new Map();
this.last = null;
this.max = max;
this.resetTtl = resetTtl;
this.size = 0;
this.ttl = ttl;
}
#has (key) {
return key in this.items;
}
clear () {
this.first = null;
this.items = Object.create(null);
this.items = new Map();
this.last = null;
this.size = 0;

@@ -35,7 +29,6 @@ return this;

delete (key) {
if (this.#has(key)) {
const item = this.items[key];
if (this.items.has(key)) {
const item = this.items.get(key);
delete this.items[key];
this.size--;
this.items.delete(key);

@@ -66,4 +59,3 @@ if (item.prev !== null) {

delete this.items[item.key];
this.size--;
this.items.delete(item.key);

@@ -85,4 +77,4 @@ if (this.size === 0) {

if (this.#has(key)) {
const item = this.items[key];
if (this.items.has(key)) {
const item = this.items.get(key);

@@ -103,4 +95,4 @@ if (this.ttl > 0 && item.expiry <= Date.now()) {

if (this.#has(key)) {
result = this.items[key].expiry;
if (this.items.has(key)) {
result = this.items.get(key).expiry;
}

@@ -112,3 +104,3 @@

keys () {
return Object.keys(this.items);
return this.items.keys();
}

@@ -119,4 +111,4 @@

if (bypass || this.#has(key)) {
item = this.items[key];
if (bypass || this.items.has(key)) {
item = this.items.get(key);
item.value = value;

@@ -154,3 +146,3 @@

item = this.items[key] = {
item = {
expiry: this.ttl > 0 ? Date.now() + this.ttl : this.ttl,

@@ -162,4 +154,5 @@ key: key,

};
this.items.set(key, item);
if (++this.size === 1) {
if (this.size === 1) {
this.first = item;

@@ -175,2 +168,6 @@ } else {

}
get size () {
return this.items.size;
}
}

@@ -177,0 +174,0 @@

/*!
2023 Jason Mulligan <jason.mulligan@avoidwork.com>
@version 10.2.2
@version 10.3.0
*/
!function(t,s){"object"==typeof exports&&"undefined"!=typeof module?s(exports):"function"==typeof define&&define.amd?define(["exports"],s):s((t="undefined"!=typeof globalThis?globalThis:t||self).lru={})}(this,(function(t){"use strict";class s{constructor(t=0,s=0,e=!1){this.first=null,this.items=Object.create(null),this.last=null,this.max=t,this.resetTtl=e,this.size=0,this.ttl=s}#t(t){return t in this.items}clear(){return this.first=null,this.items=Object.create(null),this.last=null,this.size=0,this}delete(t){if(this.#t(t)){const s=this.items[t];delete this.items[t],this.size--,null!==s.prev&&(s.prev.next=s.next),null!==s.next&&(s.next.prev=s.prev),this.first===s&&(this.first=s.next),this.last===s&&(this.last=s.prev)}return this}evict(t=!1){if(t||this.size>0){const t=this.first;delete this.items[t.key],this.size--,0===this.size?(this.first=null,this.last=null):(this.first=t.next,this.first.prev=null)}return this}get(t){let s;if(this.#t(t)){const e=this.items[t];this.ttl>0&&e.expiry<=Date.now()?this.delete(t):(s=e.value,this.set(t,s,!0))}return s}expiresAt(t){let s;return this.#t(t)&&(s=this.items[t].expiry),s}keys(){return Object.keys(this.items)}set(t,s,e=!1,i=this.resetTtl){let l;if(e||this.#t(t)){if(l=this.items[t],l.value=s,i&&(l.expiry=this.ttl>0?Date.now()+this.ttl:this.ttl),this.last!==l){const t=this.last,s=l.next,e=l.prev;this.first===l&&(this.first=l.next),l.next=null,l.prev=this.last,t.next=l,null!==e&&(e.next=s),null!==s&&(s.prev=e)}}else this.max>0&&this.size===this.max&&this.evict(!0),l=this.items[t]={expiry:this.ttl>0?Date.now()+this.ttl:this.ttl,key:t,prev:this.last,next:null,value:s},1==++this.size?this.first=l:this.last.next=l;return this.last=l,this}}t.lru=function(t=1e3,e=0,i=!1){if(isNaN(t)||t<0)throw new TypeError("Invalid max value");if(isNaN(e)||e<0)throw new TypeError("Invalid ttl value");if("boolean"!=typeof i)throw new TypeError("Invalid resetTtl value");return new s(t,e,i)}}));//# sourceMappingURL=tiny-lru.min.js.map
!function(t,e){"object"==typeof exports&&"undefined"!=typeof module?e(exports):"function"==typeof define&&define.amd?define(["exports"],e):e((t="undefined"!=typeof globalThis?globalThis:t||self).lru={})}(this,(function(t){"use strict";class e{constructor(t=0,e=0,s=!1){this.first=null,this.items=new Map,this.last=null,this.max=t,this.resetTtl=s,this.ttl=e}clear(){return this.first=null,this.items=new Map,this.last=null,this}delete(t){if(this.items.has(t)){const e=this.items.get(t);this.items.delete(t),null!==e.prev&&(e.prev.next=e.next),null!==e.next&&(e.next.prev=e.prev),this.first===e&&(this.first=e.next),this.last===e&&(this.last=e.prev)}return this}evict(t=!1){if(t||this.size>0){const t=this.first;this.items.delete(t.key),0===this.size?(this.first=null,this.last=null):(this.first=t.next,this.first.prev=null)}return this}get(t){let e;if(this.items.has(t)){const s=this.items.get(t);this.ttl>0&&s.expiry<=Date.now()?this.delete(t):(e=s.value,this.set(t,e,!0))}return e}expiresAt(t){let e;return this.items.has(t)&&(e=this.items.get(t).expiry),e}keys(){return this.items.keys()}set(t,e,s=!1,i=this.resetTtl){let l;if(s||this.items.has(t)){if(l=this.items.get(t),l.value=e,i&&(l.expiry=this.ttl>0?Date.now()+this.ttl:this.ttl),this.last!==l){const t=this.last,e=l.next,s=l.prev;this.first===l&&(this.first=l.next),l.next=null,l.prev=this.last,t.next=l,null!==s&&(s.next=e),null!==e&&(e.prev=s)}}else this.max>0&&this.size===this.max&&this.evict(!0),l={expiry:this.ttl>0?Date.now()+this.ttl:this.ttl,key:t,prev:this.last,next:null,value:e},this.items.set(t,l),1===this.size?this.first=l:this.last.next=l;return this.last=l,this}get size(){return this.items.size}}t.lru=function(t=1e3,s=0,i=!1){if(isNaN(t)||t<0)throw new TypeError("Invalid max value");if(isNaN(s)||s<0)throw new TypeError("Invalid ttl value");if("boolean"!=typeof i)throw new TypeError("Invalid resetTtl value");return new e(t,s,i)}}));//# sourceMappingURL=tiny-lru.min.js.map
{
"name": "tiny-lru",
"description": "Tiny LRU cache for Client or Server",
"version": "10.2.2",
"version": "10.3.0",
"homepage": "https://github.com/avoidwork/tiny-lru",

@@ -6,0 +6,0 @@ "author": "Jason Mulligan <jason.mulligan@avoidwork.com>",

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc