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.0.1 to 10.1.0

20

dist/tiny-lru.esm.js
/**
* tiny-lru
*
* @copyright 2022 Jason Mulligan <jason.mulligan@avoidwork.com>
* @copyright 2023 Jason Mulligan <jason.mulligan@avoidwork.com>
* @license BSD-3-Clause
* @version 10.0.1
* @version 10.1.0
*/

@@ -94,2 +94,12 @@ class LRU {

expiresAt (key) {
let result;
if (this.#has(key)) {
result = this.items[key].expiry;
}
return result;
}
keys () {

@@ -99,3 +109,3 @@ return Object.keys(this.items);

set (key, value, bypass = false) {
set (key, value, bypass = false, resetTtl = false) {
let item;

@@ -116,2 +126,6 @@

if (resetTtl) {
item.expiry = this.ttl > 0 ? new Date().getTime() + this.ttl : this.ttl;
}
item.next = null;

@@ -118,0 +132,0 @@ item.prev = this.last;

6

dist/tiny-lru.esm.min.js
/*!
2022 Jason Mulligan <jason.mulligan@avoidwork.com>
@version 10.0.1
2023 Jason Mulligan <jason.mulligan@avoidwork.com>
@version 10.1.0
*/
class t{constructor(t=0,s=0){this.first=null,this.items=Object.create(null),this.last=null,this.max=t,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 i=this.items[t];this.ttl>0&&i.expiry<=(new Date).getTime()?this.delete(t):(s=i.value,this.set(t,s,!0))}return s}keys(){return Object.keys(this.items)}set(t,s,i=!1){let e;if(i||this.#t(t)){if(e=this.items[t],e.value=s,this.last!==e){const t=this.last,s=e.next,i=e.prev;this.first===e&&(this.first=e.next),e.next=null,e.prev=this.last,t.next=e,null!==i&&(i.next=s),null!==s&&(s.prev=i)}}else this.max>0&&this.size===this.max&&this.evict(!0),e=this.items[t]={expiry:this.ttl>0?(new Date).getTime()+this.ttl:this.ttl,key:t,prev:this.last,next:null,value:s},1==++this.size?this.first=e:this.last.next=e;return this.last=e,this}}function s(s=1e3,i=0){if(isNaN(s)||s<0)throw new TypeError("Invalid max value");if(isNaN(i)||i<0)throw new TypeError("Invalid ttl value");return new t(s,i)}export{s as lru};//# sourceMappingURL=tiny-lru.esm.min.js.map
class t{constructor(t=0,s=0){this.first=null,this.items=Object.create(null),this.last=null,this.max=t,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 i=this.items[t];this.ttl>0&&i.expiry<=(new Date).getTime()?this.delete(t):(s=i.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,i=!1,e=!1){let h;if(i||this.#t(t)){if(h=this.items[t],h.value=s,this.last!==h){const t=this.last,s=h.next,i=h.prev;this.first===h&&(this.first=h.next),e&&(h.expiry=this.ttl>0?(new Date).getTime()+this.ttl:this.ttl),h.next=null,h.prev=this.last,t.next=h,null!==i&&(i.next=s),null!==s&&(s.prev=i)}}else this.max>0&&this.size===this.max&&this.evict(!0),h=this.items[t]={expiry:this.ttl>0?(new Date).getTime()+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,i=0){if(isNaN(s)||s<0)throw new TypeError("Invalid max value");if(isNaN(i)||i<0)throw new TypeError("Invalid ttl value");return new t(s,i)}export{s as lru};//# sourceMappingURL=tiny-lru.esm.min.js.map
/**
* tiny-lru
*
* @copyright 2022 Jason Mulligan <jason.mulligan@avoidwork.com>
* @copyright 2023 Jason Mulligan <jason.mulligan@avoidwork.com>
* @license BSD-3-Clause
* @version 10.0.1
* @version 10.1.0
*/

@@ -94,2 +94,12 @@ (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 {

expiresAt (key) {
let result;
if (this.#has(key)) {
result = this.items[key].expiry;
}
return result;
}
keys () {

@@ -99,3 +109,3 @@ return Object.keys(this.items);

set (key, value, bypass = false) {
set (key, value, bypass = false, resetTtl = false) {
let item;

@@ -116,2 +126,6 @@

if (resetTtl) {
item.expiry = this.ttl > 0 ? new Date().getTime() + this.ttl : this.ttl;
}
item.next = null;

@@ -165,2 +179,2 @@ item.prev = this.last;

return new LRU(max, ttl);
}exports.lru=lru;Object.defineProperty(exports,'__esModule',{value:true});}));
}exports.lru=lru;}));
/*!
2022 Jason Mulligan <jason.mulligan@avoidwork.com>
@version 10.0.1
2023 Jason Mulligan <jason.mulligan@avoidwork.com>
@version 10.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";class e{constructor(t=0,e=0){this.first=null,this.items=Object.create(null),this.last=null,this.max=t,this.size=0,this.ttl=e}#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 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],this.size--,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.#t(t)){const s=this.items[t];this.ttl>0&&s.expiry<=(new Date).getTime()?this.delete(t):(e=s.value,this.set(t,e,!0))}return e}keys(){return Object.keys(this.items)}set(t,e,s=!1){let i;if(s||this.#t(t)){if(i=this.items[t],i.value=e,this.last!==i){const t=this.last,e=i.next,s=i.prev;this.first===i&&(this.first=i.next),i.next=null,i.prev=this.last,t.next=i,null!==s&&(s.next=e),null!==e&&(e.prev=s)}}else this.max>0&&this.size===this.max&&this.evict(!0),i=this.items[t]={expiry:this.ttl>0?(new Date).getTime()+this.ttl:this.ttl,key:t,prev:this.last,next:null,value:e},1==++this.size?this.first=i:this.last.next=i;return this.last=i,this}}t.lru=function(t=1e3,s=0){if(isNaN(t)||t<0)throw new TypeError("Invalid max value");if(isNaN(s)||s<0)throw new TypeError("Invalid ttl value");return new e(t,s)},Object.defineProperty(t,"__esModule",{value:!0})}));//# 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){this.first=null,this.items=Object.create(null),this.last=null,this.max=t,this.size=0,this.ttl=e}#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 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],this.size--,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.#t(t)){const s=this.items[t];this.ttl>0&&s.expiry<=(new Date).getTime()?this.delete(t):(e=s.value,this.set(t,e,!0))}return e}expiresAt(t){let e;return this.#t(t)&&(e=this.items[t].expiry),e}keys(){return Object.keys(this.items)}set(t,e,s=!1,i=!1){let l;if(s||this.#t(t)){if(l=this.items[t],l.value=e,this.last!==l){const t=this.last,e=l.next,s=l.prev;this.first===l&&(this.first=l.next),i&&(l.expiry=this.ttl>0?(new Date).getTime()+this.ttl:this.ttl),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?(new Date).getTime()+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}}t.lru=function(t=1e3,s=0){if(isNaN(t)||t<0)throw new TypeError("Invalid max value");if(isNaN(s)||s<0)throw new TypeError("Invalid ttl value");return new e(t,s)}}));//# sourceMappingURL=tiny-lru.min.js.map

@@ -12,7 +12,8 @@ export function lru<T = any>(max?: number, ttl?: number): LRU<T>;

evict(bypass?: boolean): this;
expiresAt(key: any): number | undefined;
get(key: any): T | undefined;
keys(): string[];
set(key: any, value: T, bypass?: boolean): this;
set(key: any, value: T, bypass?: boolean, resetTtl?: boolean): this;
}
export { };
{
"name": "tiny-lru",
"description": "Tiny LRU cache for Client or Server",
"version": "10.0.1",
"version": "10.1.0",
"homepage": "https://github.com/avoidwork/tiny-lru",

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

"engines": {
"node": ">=6"
"node": ">=12"
},

@@ -39,12 +39,12 @@ "engineStrict": true,

"test-webpack": "rm -rf test/webpack && git clone git@github.com:rabelais88/typescript-webpack.git test/webpack && echo \"import { lru } from 'tiny-lru';console.log(lru(1));\" >> test/webpack/src/index.ts && cd test/webpack && npm install && mkdir -p node_modules/tiny-lru/dist && cp ../../package.json node_modules/tiny-lru/ && cp ../../dist/* node_modules/tiny-lru/dist/ && npm run build",
"types": "npx -p typescript tsc src/*.js --declaration --allowJs --emitDeclarationOnly --outDir ."
"types": "npx -p typescript tsc src/lru.js --declaration --allowJs --emitDeclarationOnly --outDir ."
},
"devDependencies": {
"@rollup/plugin-terser": "^0.4.0",
"auto-changelog": "^2.4.0",
"eslint": "^8.23.1",
"mocha": "^10.0.0",
"precise": "^2.0.0",
"rollup": "^2.79.0",
"rollup-plugin-terser": "^7.0.2",
"typescript": "^4.8.3"
"eslint": "^8.36.0",
"mocha": "^10.2.0",
"precise": "^2.0.1",
"rollup": "^3.19.1",
"typescript": "^4.9.5"
},

@@ -51,0 +51,0 @@ "keywords": [

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

## expiresAt
### Method
Gets expiration time for cached item
param {String} key Item key
return {Mixed} Undefined or number (epoch time)
**Example**
```javascript
const item = cache.expiresAt("myKey");
```
## first

@@ -146,4 +160,6 @@ ### Property

param {String} key Item key
param {Mixed} value Item value
param {String} key Item key
param {Mixed} value Item value
param {Boolean=false} bypass If set to true, this will skip cache size limit check and auto-eviction of least recently used entry on overfill.
param {Boolean=false} resetTtl If entry with this key already exists, by default it will keep same expiration date. With `resetTtl=true`, new expiration date will be calculated.
return {Object} LRU instance

@@ -184,3 +200,3 @@

## License
Copyright (c) 2022 Jason Mulligan
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

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