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 9.0.1 to 9.0.2

2

dist/tiny-lru.esm.js

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

* @license BSD-3-Clause
* @version 9.0.1
* @version 9.0.2
*/

@@ -9,0 +9,0 @@ class LRU {

/*!
2022 Jason Mulligan <jason.mulligan@avoidwork.com>
@version 9.0.1
@version 9.0.2
*/
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}has(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.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}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.has(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.has(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

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

* @license BSD-3-Clause
* @version 9.0.1
* @version 9.0.2
*/

@@ -9,0 +9,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';class LRU {

/*!
2022 Jason Mulligan <jason.mulligan@avoidwork.com>
@version 9.0.1
@version 9.0.2
*/
!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}has(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.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}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.has(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.has(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

@@ -1,18 +0,18 @@

export function lru(max?: number, ttl?: number): LRU;
declare class LRU {
constructor(max?: number, ttl?: number);
first: any;
items: any;
last: any;
export function lru<T = any>(max?: number, ttl?: number): LRU<T>;
export interface LRU<T> {
first: T | null;
last: T | null;
max: number;
size: number;
ttl: number;
has(key: any): boolean;
clear(): LRU;
delete(key: any): LRU;
evict(bypass?: boolean): LRU;
get(key: any): any;
clear(): this;
delete(key: any): this;
evict(bypass?: boolean): this;
get(key: any): T | undefined;
keys(): string[];
set(key: any, value: any, bypass?: boolean): LRU;
set(key: any, value: T, bypass?: boolean): this;
}
export {};
export { };
{
"name": "tiny-lru",
"description": "Tiny LRU cache for Client or Server",
"version": "9.0.1",
"version": "9.0.2",
"homepage": "https://github.com/avoidwork/tiny-lru",

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

"scripts": {
"build": "npm run lint && rm -rf dist/* && npm run rollup && npm run types && npm run mocha",
"build": "npm run lint && rm -rf dist/* && npm run rollup && npm run mocha",
"benchmark": "node benchmark.js",

@@ -34,0 +34,0 @@ "changelog": "auto-changelog -p",

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