Socket
Socket
Sign inDemoInstall

tiny-lru

Package Overview
Dependencies
Maintainers
1
Versions
102
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

tiny-lru - npm Package Compare versions

Comparing version 11.0.1 to 11.1.0

26

dist/tiny-lru.js

@@ -6,7 +6,5 @@ /**

* @license BSD-3-Clause
* @version 11.0.0
* @version 11.1.0
*/
function has (items, key) {
return key in items;
}class LRU {
class LRU {
constructor (max = 0, ttl = 0, resetTtl = false) {

@@ -32,3 +30,3 @@ this.first = null;

delete (key) {
if (has(this.items, key)) {
if (this.has(key)) {
const item = this.items[key];

@@ -59,2 +57,6 @@

entries (keys = this.keys()) {
return keys.map(key => [key, this.get(key)]);
}
evict (bypass = false) {

@@ -81,3 +83,3 @@ if (bypass || this.size > 0) {

if (has(this.items, key)) {
if (this.has(key)) {
result = this.items[key].expiry;

@@ -92,3 +94,3 @@ }

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

@@ -107,2 +109,6 @@

has (key) {
return key in this.items;
}
keys () {

@@ -115,3 +121,3 @@ return Object.keys(this.items);

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

@@ -169,2 +175,6 @@ item.value = value;

}
values (keys = this.keys()) {
return keys.map(key => this.get(key));
}
}

@@ -171,0 +181,0 @@

/*!
2023 Jason Mulligan <jason.mulligan@avoidwork.com>
@version 11.0.0
@version 11.1.0
*/
function t(t,s){return s in t}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}clear(){return this.first=null,this.items=Object.create(null),this.last=null,this.size=0,this}delete(s){if(t(this.items,s)){const t=this.items[s];delete this.items[s],this.size--,null!==t.prev&&(t.prev.next=t.next),null!==t.next&&(t.next.prev=t.prev),this.first===t&&(this.first=t.next),this.last===t&&(this.last=t.prev)}return this}evict(t=!1){if(t||this.size>0){const t=this.first;delete this.items[t.key],0==--this.size?(this.first=null,this.last=null):(this.first=t.next,this.first.prev=null)}return this}expiresAt(s){let e;return t(this.items,s)&&(e=this.items[s].expiry),e}get(s){let e;if(t(this.items,s)){const t=this.items[s];this.ttl>0&&t.expiry<=Date.now()?this.delete(s):(e=t.value,this.set(s,e,!0))}return e}keys(){return Object.keys(this.items)}set(s,e,i=!1,l=this.resetTtl){let h;if(i||t(this.items,s)){if(h=this.items[s],h.value=e,l&&(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[s]={expiry:this.ttl>0?Date.now()+this.ttl:this.ttl,key:s,prev:this.last,next:null,value:e},1==++this.size?this.first=h:this.last.next=h;return this.last=h,this}}function e(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)}export{e as lru};//# sourceMappingURL=tiny-lru.min.js.map
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}clear(){return this.first=null,this.items=Object.create(null),this.last=null,this.size=0,this}delete(t){if(this.has(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}entries(t=this.keys()){return t.map((t=>[t,this.get(t)]))}evict(t=!1){if(t||this.size>0){const t=this.first;delete this.items[t.key],0==--this.size?(this.first=null,this.last=null):(this.first=t.next,this.first.prev=null)}return this}expiresAt(t){let s;return this.has(t)&&(s=this.items[t].expiry),s}get(t){let s;if(this.has(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}has(t){return t in this.items}keys(){return Object.keys(this.items)}set(t,s,e=!1,i=this.resetTtl){let h;if(e||this.has(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}values(t=this.keys()){return t.map((t=>this.get(t)))}}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.min.js.map

@@ -6,7 +6,5 @@ /**

* @license BSD-3-Clause
* @version 11.0.0
* @version 11.1.0
*/
(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';function has (items, key) {
return key in items;
}class LRU {
(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 {
constructor (max = 0, ttl = 0, resetTtl = false) {

@@ -32,3 +30,3 @@ this.first = null;

delete (key) {
if (has(this.items, key)) {
if (this.has(key)) {
const item = this.items[key];

@@ -59,2 +57,6 @@

entries (keys = this.keys()) {
return keys.map(key => [key, this.get(key)]);
}
evict (bypass = false) {

@@ -81,3 +83,3 @@ if (bypass || this.size > 0) {

if (has(this.items, key)) {
if (this.has(key)) {
result = this.items[key].expiry;

@@ -92,3 +94,3 @@ }

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

@@ -107,2 +109,6 @@

has (key) {
return key in this.items;
}
keys () {

@@ -115,3 +121,3 @@ return Object.keys(this.items);

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

@@ -169,2 +175,6 @@ item.value = value;

}
values (keys = this.keys()) {
return keys.map(key => this.get(key));
}
}

@@ -171,0 +181,0 @@

/*!
2023 Jason Mulligan <jason.mulligan@avoidwork.com>
@version 11.0.0
@version 11.1.0
*/
!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";function e(t,e){return e in t}class s{constructor(t=0,e=0,s=!1){this.first=null,this.items=Object.create(null),this.last=null,this.max=t,this.resetTtl=s,this.size=0,this.ttl=e}clear(){return this.first=null,this.items=Object.create(null),this.last=null,this.size=0,this}delete(t){if(e(this.items,t)){const e=this.items[t];delete this.items[t],this.size--,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;delete this.items[t.key],0==--this.size?(this.first=null,this.last=null):(this.first=t.next,this.first.prev=null)}return this}expiresAt(t){let s;return e(this.items,t)&&(s=this.items[t].expiry),s}get(t){let s;if(e(this.items,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}keys(){return Object.keys(this.items)}set(t,s,i=!1,l=this.resetTtl){let n;if(i||e(this.items,t)){if(n=this.items[t],n.value=s,l&&(n.expiry=this.ttl>0?Date.now()+this.ttl:this.ttl),this.last!==n){const t=this.last,e=n.next,s=n.prev;this.first===n&&(this.first=n.next),n.next=null,n.prev=this.last,t.next=n,null!==s&&(s.next=e),null!==e&&(e.prev=s)}}else this.max>0&&this.size===this.max&&this.evict(!0),n=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=n:this.last.next=n;return this.last=n,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.umd.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=Object.create(null),this.last=null,this.max=t,this.resetTtl=s,this.size=0,this.ttl=e}clear(){return this.first=null,this.items=Object.create(null),this.last=null,this.size=0,this}delete(t){if(this.has(t)){const e=this.items[t];delete this.items[t],this.size--,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}entries(t=this.keys()){return t.map((t=>[t,this.get(t)]))}evict(t=!1){if(t||this.size>0){const t=this.first;delete this.items[t.key],0==--this.size?(this.first=null,this.last=null):(this.first=t.next,this.first.prev=null)}return this}expiresAt(t){let e;return this.has(t)&&(e=this.items[t].expiry),e}get(t){let e;if(this.has(t)){const s=this.items[t];this.ttl>0&&s.expiry<=Date.now()?this.delete(t):(e=s.value,this.set(t,e,!0))}return e}has(t){return t in this.items}keys(){return Object.keys(this.items)}set(t,e,s=!1,i=this.resetTtl){let l;if(s||this.has(t)){if(l=this.items[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=this.items[t]={expiry:this.ttl>0?Date.now()+this.ttl:this.ttl,key:t,prev:this.last,next:null,value:e},1==++this.size?this.first=l:this.last.next=l;return this.last=l,this}values(t=this.keys()){return t.map((t=>this.get(t)))}}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.umd.min.js.map
{
"name": "tiny-lru",
"description": "Tiny LRU cache for Client or Server",
"version": "11.0.1",
"version": "11.1.0",
"homepage": "https://github.com/avoidwork/tiny-lru",

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

@@ -47,2 +47,16 @@ # Tiny LRU

## entries(*["key1", "key2"]*)
### Method
Returns an `Array` cache items
param {Array} keys (Optional) Cache item keys to get
return {Object} LRU instance
**Example**
```javascript
cache.entries(['myKey1', 'myKey2']);
```
## evict

@@ -102,2 +116,15 @@ ### Method

## has
### Method
Returns a `Boolean` indicating if `key` is in cache
return {Object} LRU instance
**Example**
```javascript
cache.has('myKey');
```
## keys

@@ -196,4 +223,18 @@ ### Method

## values(*["key1", "key2"]*)
### Method
Returns an `Array` cache items
param {Array} keys (Optional) Cache item keys to get
return {Array} Cache items
**Example**
```javascript
cache.values(['abc', 'def']);
```
## License
Copyright (c) 2023 Jason Mulligan
Licensed under the BSD-3 license.

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
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc