From 0d0887458527c8c41f632a7688d3a17e45723886 Mon Sep 17 00:00:00 2001 From: Jason Mulligan Date: Thu, 27 Oct 2022 21:46:19 -0400 Subject: [PATCH] Changing `has()` to be private as `#has()`, updating eslint rules --- .eslintrc | 2 +- dist/tiny-lru.cjs | 10 +++++----- dist/tiny-lru.esm.js | 10 +++++----- dist/tiny-lru.esm.min.js | 4 ++-- dist/tiny-lru.esm.min.js.map | 2 +- dist/tiny-lru.js | 10 +++++----- dist/tiny-lru.min.js | 4 ++-- dist/tiny-lru.min.js.map | 2 +- package-lock.json | 4 ++-- package.json | 2 +- src/lru.js | 8 ++++---- 11 files changed, 29 insertions(+), 29 deletions(-) diff --git a/.eslintrc b/.eslintrc index f34ead6..f818ced 100644 --- a/.eslintrc +++ b/.eslintrc @@ -6,7 +6,7 @@ "amd": true }, "parserOptions": { - "ecmaVersion": 2020, + "ecmaVersion": "latest", "sourceType": "module" }, "globals": { diff --git a/dist/tiny-lru.cjs b/dist/tiny-lru.cjs index 6fb7c97..8cb82a0 100644 --- a/dist/tiny-lru.cjs +++ b/dist/tiny-lru.cjs @@ -3,7 +3,7 @@ * * @copyright 2022 Jason Mulligan * @license BSD-3-Clause - * @version 9.0.3 + * @version 10.0.0 */ 'use strict'; @@ -19,7 +19,7 @@ class LRU { this.ttl = ttl; } - has (key) { + #has (key) { return key in this.items; } @@ -33,7 +33,7 @@ class LRU { } delete (key) { - if (this.has(key)) { + if (this.#has(key)) { const item = this.items[key]; delete this.items[key]; @@ -81,7 +81,7 @@ class LRU { get (key) { let result; - if (this.has(key)) { + if (this.#has(key)) { const item = this.items[key]; if (this.ttl > 0 && item.expiry <= new Date().getTime()) { @@ -102,7 +102,7 @@ class LRU { set (key, value, bypass = false) { let item; - if (bypass || this.has(key)) { + if (bypass || this.#has(key)) { item = this.items[key]; item.value = value; diff --git a/dist/tiny-lru.esm.js b/dist/tiny-lru.esm.js index b26e83f..ae2a018 100644 --- a/dist/tiny-lru.esm.js +++ b/dist/tiny-lru.esm.js @@ -3,7 +3,7 @@ * * @copyright 2022 Jason Mulligan * @license BSD-3-Clause - * @version 9.0.3 + * @version 10.0.0 */ class LRU { constructor (max = 0, ttl = 0) { @@ -15,7 +15,7 @@ class LRU { this.ttl = ttl; } - has (key) { + #has (key) { return key in this.items; } @@ -29,7 +29,7 @@ class LRU { } delete (key) { - if (this.has(key)) { + if (this.#has(key)) { const item = this.items[key]; delete this.items[key]; @@ -77,7 +77,7 @@ class LRU { get (key) { let result; - if (this.has(key)) { + if (this.#has(key)) { const item = this.items[key]; if (this.ttl > 0 && item.expiry <= new Date().getTime()) { @@ -98,7 +98,7 @@ class LRU { set (key, value, bypass = false) { let item; - if (bypass || this.has(key)) { + if (bypass || this.#has(key)) { item = this.items[key]; item.value = value; diff --git a/dist/tiny-lru.esm.min.js b/dist/tiny-lru.esm.min.js index 5204e5e..7fafa5f 100644 --- a/dist/tiny-lru.esm.min.js +++ b/dist/tiny-lru.esm.min.js @@ -1,5 +1,5 @@ /*! 2022 Jason Mulligan - @version 9.0.3 + @version 10.0.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}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 +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 diff --git a/dist/tiny-lru.esm.min.js.map b/dist/tiny-lru.esm.min.js.map index f3460a5..f444009 100644 --- a/dist/tiny-lru.esm.min.js.map +++ b/dist/tiny-lru.esm.min.js.map @@ -1 +1 @@ -{"version":3,"file":"tiny-lru.esm.min.js","sources":["../src/lru.js"],"sourcesContent":["class LRU {\n\tconstructor (max = 0, ttl = 0) {\n\t\tthis.first = null;\n\t\tthis.items = Object.create(null);\n\t\tthis.last = null;\n\t\tthis.max = max;\n\t\tthis.size = 0;\n\t\tthis.ttl = ttl;\n\t}\n\n\thas (key) {\n\t\treturn key in this.items;\n\t}\n\n\tclear () {\n\t\tthis.first = null;\n\t\tthis.items = Object.create(null);\n\t\tthis.last = null;\n\t\tthis.size = 0;\n\n\t\treturn this;\n\t}\n\n\tdelete (key) {\n\t\tif (this.has(key)) {\n\t\t\tconst item = this.items[key];\n\n\t\t\tdelete this.items[key];\n\t\t\tthis.size--;\n\n\t\t\tif (item.prev !== null) {\n\t\t\t\titem.prev.next = item.next;\n\t\t\t}\n\n\t\t\tif (item.next !== null) {\n\t\t\t\titem.next.prev = item.prev;\n\t\t\t}\n\n\t\t\tif (this.first === item) {\n\t\t\t\tthis.first = item.next;\n\t\t\t}\n\n\t\t\tif (this.last === item) {\n\t\t\t\tthis.last = item.prev;\n\t\t\t}\n\t\t}\n\n\t\treturn this;\n\t}\n\n\tevict (bypass = false) {\n\t\tif (bypass || this.size > 0) {\n\t\t\tconst item = this.first;\n\n\t\t\tdelete this.items[item.key];\n\t\t\tthis.size--;\n\n\t\t\tif (this.size === 0) {\n\t\t\t\tthis.first = null;\n\t\t\t\tthis.last = null;\n\t\t\t} else {\n\t\t\t\tthis.first = item.next;\n\t\t\t\tthis.first.prev = null;\n\t\t\t}\n\t\t}\n\n\t\treturn this;\n\t}\n\n\tget (key) {\n\t\tlet result;\n\n\t\tif (this.has(key)) {\n\t\t\tconst item = this.items[key];\n\n\t\t\tif (this.ttl > 0 && item.expiry <= new Date().getTime()) {\n\t\t\t\tthis.delete(key);\n\t\t\t} else {\n\t\t\t\tresult = item.value;\n\t\t\t\tthis.set(key, result, true);\n\t\t\t}\n\t\t}\n\n\t\treturn result;\n\t}\n\n\tkeys () {\n\t\treturn Object.keys(this.items);\n\t}\n\n\tset (key, value, bypass = false) {\n\t\tlet item;\n\n\t\tif (bypass || this.has(key)) {\n\t\t\titem = this.items[key];\n\t\t\titem.value = value;\n\n\t\t\tif (this.last !== item) {\n\t\t\t\tconst last = this.last,\n\t\t\t\t\tnext = item.next,\n\t\t\t\t\tprev = item.prev;\n\n\t\t\t\tif (this.first === item) {\n\t\t\t\t\tthis.first = item.next;\n\t\t\t\t}\n\n\t\t\t\titem.next = null;\n\t\t\t\titem.prev = this.last;\n\t\t\t\tlast.next = item;\n\n\t\t\t\tif (prev !== null) {\n\t\t\t\t\tprev.next = next;\n\t\t\t\t}\n\n\t\t\t\tif (next !== null) {\n\t\t\t\t\tnext.prev = prev;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (this.max > 0 && this.size === this.max) {\n\t\t\t\tthis.evict(true);\n\t\t\t}\n\n\t\t\titem = this.items[key] = {\n\t\t\t\texpiry: this.ttl > 0 ? new Date().getTime() + this.ttl : this.ttl,\n\t\t\t\tkey: key,\n\t\t\t\tprev: this.last,\n\t\t\t\tnext: null,\n\t\t\t\tvalue\n\t\t\t};\n\n\t\t\tif (++this.size === 1) {\n\t\t\t\tthis.first = item;\n\t\t\t} else {\n\t\t\t\tthis.last.next = item;\n\t\t\t}\n\t\t}\n\n\t\tthis.last = item;\n\n\t\treturn this;\n\t}\n}\n\nexport function lru (max = 1000, ttl = 0) {\n\tif (isNaN(max) || max < 0) {\n\t\tthrow new TypeError(\"Invalid max value\");\n\t}\n\n\tif (isNaN(ttl) || ttl < 0) {\n\t\tthrow new TypeError(\"Invalid ttl value\");\n\t}\n\n\treturn new LRU(max, ttl);\n}\n"],"names":["LRU","constructor","max","ttl","this","first","items","Object","create","last","size","has","key","clear","delete","item","prev","next","evict","bypass","get","result","expiry","Date","getTime","value","set","keys","lru","isNaN","TypeError"],"mappings":";;;;AAAA,MAAMA,EACLC,YAAaC,EAAM,EAAGC,EAAM,GAC3BC,KAAKC,MAAQ,KACbD,KAAKE,MAAQC,OAAOC,OAAO,MAC3BJ,KAAKK,KAAO,KACZL,KAAKF,IAAMA,EACXE,KAAKM,KAAO,EACZN,KAAKD,IAAMA,CACX,CAEDQ,IAAKC,GACJ,OAAOA,KAAOR,KAAKE,KACnB,CAEDO,QAMC,OALAT,KAAKC,MAAQ,KACbD,KAAKE,MAAQC,OAAOC,OAAO,MAC3BJ,KAAKK,KAAO,KACZL,KAAKM,KAAO,EAELN,IACP,CAEDU,OAAQF,GACP,GAAIR,KAAKO,IAAIC,GAAM,CAClB,MAAMG,EAAOX,KAAKE,MAAMM,UAEjBR,KAAKE,MAAMM,GAClBR,KAAKM,OAEa,OAAdK,EAAKC,OACRD,EAAKC,KAAKC,KAAOF,EAAKE,MAGL,OAAdF,EAAKE,OACRF,EAAKE,KAAKD,KAAOD,EAAKC,MAGnBZ,KAAKC,QAAUU,IAClBX,KAAKC,MAAQU,EAAKE,MAGfb,KAAKK,OAASM,IACjBX,KAAKK,KAAOM,EAAKC,KAElB,CAED,OAAOZ,IACP,CAEDc,MAAOC,GAAS,GACf,GAAIA,GAAUf,KAAKM,KAAO,EAAG,CAC5B,MAAMK,EAAOX,KAAKC,aAEXD,KAAKE,MAAMS,EAAKH,KACvBR,KAAKM,OAEa,IAAdN,KAAKM,MACRN,KAAKC,MAAQ,KACbD,KAAKK,KAAO,OAEZL,KAAKC,MAAQU,EAAKE,KAClBb,KAAKC,MAAMW,KAAO,KAEnB,CAED,OAAOZ,IACP,CAEDgB,IAAKR,GACJ,IAAIS,EAEJ,GAAIjB,KAAKO,IAAIC,GAAM,CAClB,MAAMG,EAAOX,KAAKE,MAAMM,GAEpBR,KAAKD,IAAM,GAAKY,EAAKO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src/lru.js"],"sourcesContent":["class LRU {\n\tconstructor (max = 0, ttl = 0) {\n\t\tthis.first = null;\n\t\tthis.items = Object.create(null);\n\t\tthis.last = null;\n\t\tthis.max = max;\n\t\tthis.size = 0;\n\t\tthis.ttl = ttl;\n\t}\n\n\t#has (key) {\n\t\treturn key in this.items;\n\t}\n\n\tclear () {\n\t\tthis.first = null;\n\t\tthis.items = Object.create(null);\n\t\tthis.last = null;\n\t\tthis.size = 0;\n\n\t\treturn this;\n\t}\n\n\tdelete (key) {\n\t\tif (this.#has(key)) {\n\t\t\tconst item = this.items[key];\n\n\t\t\tdelete this.items[key];\n\t\t\tthis.size--;\n\n\t\t\tif (item.prev !== null) {\n\t\t\t\titem.prev.next = item.next;\n\t\t\t}\n\n\t\t\tif (item.next !== null) {\n\t\t\t\titem.next.prev = item.prev;\n\t\t\t}\n\n\t\t\tif (this.first === item) {\n\t\t\t\tthis.first = item.next;\n\t\t\t}\n\n\t\t\tif (this.last === item) {\n\t\t\t\tthis.last = item.prev;\n\t\t\t}\n\t\t}\n\n\t\treturn this;\n\t}\n\n\tevict (bypass = false) {\n\t\tif (bypass || this.size > 0) {\n\t\t\tconst item = this.first;\n\n\t\t\tdelete this.items[item.key];\n\t\t\tthis.size--;\n\n\t\t\tif (this.size === 0) {\n\t\t\t\tthis.first = null;\n\t\t\t\tthis.last = null;\n\t\t\t} else {\n\t\t\t\tthis.first = item.next;\n\t\t\t\tthis.first.prev = null;\n\t\t\t}\n\t\t}\n\n\t\treturn this;\n\t}\n\n\tget (key) {\n\t\tlet result;\n\n\t\tif (this.#has(key)) {\n\t\t\tconst item = this.items[key];\n\n\t\t\tif (this.ttl > 0 && item.expiry <= new Date().getTime()) {\n\t\t\t\tthis.delete(key);\n\t\t\t} else {\n\t\t\t\tresult = item.value;\n\t\t\t\tthis.set(key, result, true);\n\t\t\t}\n\t\t}\n\n\t\treturn result;\n\t}\n\n\tkeys () {\n\t\treturn Object.keys(this.items);\n\t}\n\n\tset (key, value, bypass = false) {\n\t\tlet item;\n\n\t\tif (bypass || this.#has(key)) {\n\t\t\titem = this.items[key];\n\t\t\titem.value = value;\n\n\t\t\tif (this.last !== item) {\n\t\t\t\tconst last = this.last,\n\t\t\t\t\tnext = item.next,\n\t\t\t\t\tprev = item.prev;\n\n\t\t\t\tif (this.first === item) {\n\t\t\t\t\tthis.first = item.next;\n\t\t\t\t}\n\n\t\t\t\titem.next = null;\n\t\t\t\titem.prev = this.last;\n\t\t\t\tlast.next = item;\n\n\t\t\t\tif (prev !== null) {\n\t\t\t\t\tprev.next = next;\n\t\t\t\t}\n\n\t\t\t\tif (next !== null) {\n\t\t\t\t\tnext.prev = prev;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (this.max > 0 && this.size === this.max) {\n\t\t\t\tthis.evict(true);\n\t\t\t}\n\n\t\t\titem = this.items[key] = {\n\t\t\t\texpiry: this.ttl > 0 ? new Date().getTime() + this.ttl : this.ttl,\n\t\t\t\tkey: key,\n\t\t\t\tprev: this.last,\n\t\t\t\tnext: null,\n\t\t\t\tvalue\n\t\t\t};\n\n\t\t\tif (++this.size === 1) {\n\t\t\t\tthis.first = item;\n\t\t\t} else {\n\t\t\t\tthis.last.next = item;\n\t\t\t}\n\t\t}\n\n\t\tthis.last = item;\n\n\t\treturn this;\n\t}\n}\n\nexport function lru (max = 1000, ttl = 0) {\n\tif (isNaN(max) || max < 0) {\n\t\tthrow new TypeError(\"Invalid max value\");\n\t}\n\n\tif (isNaN(ttl) || ttl < 0) {\n\t\tthrow new TypeError(\"Invalid ttl value\");\n\t}\n\n\treturn new LRU(max, ttl);\n}\n"],"names":["LRU","constructor","max","ttl","this","first","items","Object","create","last","size","has","key","clear","delete","item","prev","next","evict","bypass","get","result","expiry","Date","getTime","value","set","keys","lru","isNaN","TypeError"],"mappings":";;;;AAAA,MAAMA,EACLC,YAAaC,EAAM,EAAGC,EAAM,GAC3BC,KAAKC,MAAQ,KACbD,KAAKE,MAAQC,OAAOC,OAA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S,GACzB,IAAIJ,EAEJ,GAAII,GAAUf,MAAKO,EAAKC,IAIvB,GAHAG,EAAOX,KAAKE,MAAMM,GAClBG,EAAKU,MAAQA,EAETrB,KAAKK,OAASM,EAAM,CACvB,MAAMN,EAAOL,KAAKK,KACjBQ,EAAOF,EAAKE,KACZD,EAAOD,EAAKC,KAETZ,KAAKC,QAAUU,IAClBX,KAAKC,MAAQU,EAAKE,MAGnBF,EAAKE,KAAO,KACZF,EAAKC,KAAOZ,KAAKK,KACjBA,EAAKQ,KAAOF,EAEC,OAATC,IACHA,EAAKC,KAAOA,GAGA,OAATA,IACHA,EAAKD,KAAOA,EAEb,OAEGZ,KAAKF,IAAM,GAAKE,KAAKM,OAASN,KAAKF,KACtCE,KAAKc,OAAM,GAGZH,EAAOX,KAAKE,MAAMM,GAAO,CACxBU,OAAQlB,KAAKD,IAAM,GAAI,IAAIoB,MAAOC,UAAYpB,KAAKD,IAAMC,KAAKD,IAC9DS,IAAKA,EACLI,KAAMZ,KAAKK,KACXQ,KAAM,KACNQ,SAGmB,KAAdrB,KAAKM,KACVN,KAAKC,MAAQU,EAEbX,KAAKK,KAAKQ,KAAOF,EAMnB,OAFAX,KAAKK,KAAOM,EAELX,IACP,EAGK,SAASwB,EAAK1B,EAAM,IAAMC,EAAM,GACtC,GAAI0B,MAAM3B,IAAQA,EAAM,EACvB,MAAM,IAAI4B,UAAU,qBAGrB,GAAID,MAAM1B,IAAQA,EAAM,EACvB,MAAM,IAAI2B,UAAU,qBAGrB,OAAO,IAAI9B,EAAIE,EAAKC,EACrB,QAAAyB"} \ No newline at end of file diff --git a/dist/tiny-lru.js b/dist/tiny-lru.js index 91ec766..c5c6f9a 100644 --- a/dist/tiny-lru.js +++ b/dist/tiny-lru.js @@ -3,7 +3,7 @@ * * @copyright 2022 Jason Mulligan * @license BSD-3-Clause - * @version 9.0.3 + * @version 10.0.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 { constructor (max = 0, ttl = 0) { @@ -15,7 +15,7 @@ this.ttl = ttl; } - has (key) { + #has (key) { return key in this.items; } @@ -29,7 +29,7 @@ } delete (key) { - if (this.has(key)) { + if (this.#has(key)) { const item = this.items[key]; delete this.items[key]; @@ -77,7 +77,7 @@ get (key) { let result; - if (this.has(key)) { + if (this.#has(key)) { const item = this.items[key]; if (this.ttl > 0 && item.expiry <= new Date().getTime()) { @@ -98,7 +98,7 @@ set (key, value, bypass = false) { let item; - if (bypass || this.has(key)) { + if (bypass || this.#has(key)) { item = this.items[key]; item.value = value; diff --git a/dist/tiny-lru.min.js b/dist/tiny-lru.min.js index a0c7d23..a0a0c8a 100644 --- a/dist/tiny-lru.min.js +++ b/dist/tiny-lru.min.js @@ -1,5 +1,5 @@ /*! 2022 Jason Mulligan - @version 9.0.3 + @version 10.0.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}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 +!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 diff --git a/dist/tiny-lru.min.js.map b/dist/tiny-lru.min.js.map index a49b05f..960e26e 100644 --- a/dist/tiny-lru.min.js.map +++ b/dist/tiny-lru.min.js.map @@ -1 +1 @@ -{"version":3,"file":"tiny-lru.min.js","sources":["../src/lru.js"],"sourcesContent":["class LRU {\n\tconstructor (max = 0, ttl = 0) {\n\t\tthis.first = null;\n\t\tthis.items = Object.create(null);\n\t\tthis.last = null;\n\t\tthis.max = max;\n\t\tthis.size = 0;\n\t\tthis.ttl = ttl;\n\t}\n\n\thas (key) {\n\t\treturn key in this.items;\n\t}\n\n\tclear () {\n\t\tthis.first = null;\n\t\tthis.items = Object.create(null);\n\t\tthis.last = null;\n\t\tthis.size = 0;\n\n\t\treturn this;\n\t}\n\n\tdelete (key) {\n\t\tif (this.has(key)) {\n\t\t\tconst item = this.items[key];\n\n\t\t\tdelete this.items[key];\n\t\t\tthis.size--;\n\n\t\t\tif (item.prev !== null) {\n\t\t\t\titem.prev.next = item.next;\n\t\t\t}\n\n\t\t\tif (item.next !== null) {\n\t\t\t\titem.next.prev = item.prev;\n\t\t\t}\n\n\t\t\tif (this.first === item) {\n\t\t\t\tthis.first = item.next;\n\t\t\t}\n\n\t\t\tif (this.last === item) {\n\t\t\t\tthis.last = item.prev;\n\t\t\t}\n\t\t}\n\n\t\treturn this;\n\t}\n\n\tevict (bypass = false) {\n\t\tif (bypass || this.size > 0) {\n\t\t\tconst item = this.first;\n\n\t\t\tdelete this.items[item.key];\n\t\t\tthis.size--;\n\n\t\t\tif (this.size === 0) {\n\t\t\t\tthis.first = null;\n\t\t\t\tthis.last = null;\n\t\t\t} else {\n\t\t\t\tthis.first = item.next;\n\t\t\t\tthis.first.prev = null;\n\t\t\t}\n\t\t}\n\n\t\treturn this;\n\t}\n\n\tget (key) {\n\t\tlet result;\n\n\t\tif (this.has(key)) {\n\t\t\tconst item = this.items[key];\n\n\t\t\tif (this.ttl > 0 && item.expiry <= new Date().getTime()) {\n\t\t\t\tthis.delete(key);\n\t\t\t} else {\n\t\t\t\tresult = item.value;\n\t\t\t\tthis.set(key, result, true);\n\t\t\t}\n\t\t}\n\n\t\treturn result;\n\t}\n\n\tkeys () {\n\t\treturn Object.keys(this.items);\n\t}\n\n\tset (key, value, bypass = false) {\n\t\tlet item;\n\n\t\tif (bypass || this.has(key)) {\n\t\t\titem = this.items[key];\n\t\t\titem.value = value;\n\n\t\t\tif (this.last !== item) {\n\t\t\t\tconst last = this.last,\n\t\t\t\t\tnext = item.next,\n\t\t\t\t\tprev = item.prev;\n\n\t\t\t\tif (this.first === item) {\n\t\t\t\t\tthis.first = item.next;\n\t\t\t\t}\n\n\t\t\t\titem.next = null;\n\t\t\t\titem.prev = this.last;\n\t\t\t\tlast.next = item;\n\n\t\t\t\tif (prev !== null) {\n\t\t\t\t\tprev.next = next;\n\t\t\t\t}\n\n\t\t\t\tif (next !== null) {\n\t\t\t\t\tnext.prev = prev;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (this.max > 0 && this.size === this.max) {\n\t\t\t\tthis.evict(true);\n\t\t\t}\n\n\t\t\titem = this.items[key] = {\n\t\t\t\texpiry: this.ttl > 0 ? new Date().getTime() + this.ttl : this.ttl,\n\t\t\t\tkey: key,\n\t\t\t\tprev: this.last,\n\t\t\t\tnext: null,\n\t\t\t\tvalue\n\t\t\t};\n\n\t\t\tif (++this.size === 1) {\n\t\t\t\tthis.first = item;\n\t\t\t} else {\n\t\t\t\tthis.last.next = item;\n\t\t\t}\n\t\t}\n\n\t\tthis.last = item;\n\n\t\treturn this;\n\t}\n}\n\nexport function lru (max = 1000, ttl = 0) {\n\tif (isNaN(max) || max < 0) {\n\t\tthrow new TypeError(\"Invalid max value\");\n\t}\n\n\tif (isNaN(ttl) || ttl < 0) {\n\t\tthrow new TypeError(\"Invalid ttl value\");\n\t}\n\n\treturn new LRU(max, ttl);\n}\n"],"names":["g","f","exports","module","define","amd","globalThis","self","lru","this","LRU","constructor","max","ttl","first","items","Object","create","last","size","has","key","clear","delete","item","prev","next","evict","bypass","get","result","expiry","Date","getTime","value","set","keys","isNaN","TypeError","defineProperty"],"mappings":";;;;CAAA,SAAAA,EAAAC,GAAA,iBAAAC,SAAA,oBAAAC,OAAAF,EAAAC,SAAA,mBAAAE,QAAAA,OAAAC,IAAAD,OAAA,CAAA,WAAAH,GAAAA,GAAAD,EAAA,oBAAAM,WAAAA,WAAAN,GAAAO,MAAAC,IAAA,CAAA,EAAA,CAAA,CAAAC,MAAA,SAAAP,GAAA,aAAA,MAAMQ,EACLC,YAAaC,EAAM,EAAGC,EAAM,GAC3BJ,KAAKK,MAAQ,KACbL,KAAKM,MAAQC,OAAOC,OAAO,MAC3BR,KAAKS,KAAO,KACZT,KAAKG,IAAMA,EACXH,KAAKU,KAAO,EACZV,KAAKI,IAAMA,CACX,CAEDO,IAAKC,GACJ,OAAOA,KAAOZ,KAAKM,KACnB,CAEDO,QAMC,OALAb,KAAKK,MAAQ,KACbL,KAAKM,MAAQC,OAAOC,OAAO,MAC3BR,KAAKS,KAAO,KACZT,KAAKU,KAAO,EAELV,IACP,CAEDc,OAAQF,GACP,GAAIZ,KAAKW,IAAIC,GAAM,CAClB,MAAMG,EAAOf,KAAKM,MAAMM,UAEjBZ,KAAKM,MAAMM,GAClBZ,KAAKU,OAEa,OAAdK,EAAKC,OACRD,EAAKC,KAAKC,KAAOF,EAAKE,MAGL,OAAdF,EAAKE,OACRF,EAAKE,KAAKD,KAAOD,EAAKC,MAGnBhB,KAAKK,QAAUU,IAClBf,KAAKK,MAAQU,EAAKE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AM,GAAI,IAAImB,MAAOC,UAAYxB,KAAKI,IAAMJ,KAAKI,IAC9DQ,IAAKA,EACLI,KAAMhB,KAAKS,KACXQ,KAAM,KACNQ,SAGmB,KAAdzB,KAAKU,KACVV,KAAKK,MAAQU,EAEbf,KAAKS,KAAKQ,KAAOF,EAMnB,OAFAf,KAAKS,KAAOM,EAELf,IACP,EAaFP,EAAAM,IAVO,SAAcI,EAAM,IAAMC,EAAM,GACtC,GAAIwB,MAAMzB,IAAQA,EAAM,EACvB,MAAM,IAAI0B,UAAU,qBAGrB,GAAID,MAAMxB,IAAQA,EAAM,EACvB,MAAM,IAAIyB,UAAU,qBAGrB,OAAO,IAAI5B,EAAIE,EAAKC,EACrB,EAAAG,OAAAuB,eAAArC,EAAA,aAAA,CAAAgC,OAAA,GAAA"} \ No newline at end of file +{"version":3,"file":"tiny-lru.min.js","sources":["../src/lru.js"],"sourcesContent":["class LRU {\n\tconstructor (max = 0, ttl = 0) {\n\t\tthis.first = null;\n\t\tthis.items = Object.create(null);\n\t\tthis.last = null;\n\t\tthis.max = max;\n\t\tthis.size = 0;\n\t\tthis.ttl = ttl;\n\t}\n\n\t#has (key) {\n\t\treturn key in this.items;\n\t}\n\n\tclear () {\n\t\tthis.first = null;\n\t\tthis.items = Object.create(null);\n\t\tthis.last = null;\n\t\tthis.size = 0;\n\n\t\treturn this;\n\t}\n\n\tdelete (key) {\n\t\tif (this.#has(key)) {\n\t\t\tconst item = this.items[key];\n\n\t\t\tdelete this.items[key];\n\t\t\tthis.size--;\n\n\t\t\tif (item.prev !== null) {\n\t\t\t\titem.prev.next = item.next;\n\t\t\t}\n\n\t\t\tif (item.next !== null) {\n\t\t\t\titem.next.prev = item.prev;\n\t\t\t}\n\n\t\t\tif (this.first === item) {\n\t\t\t\tthis.first = item.next;\n\t\t\t}\n\n\t\t\tif (this.last === item) {\n\t\t\t\tthis.last = item.prev;\n\t\t\t}\n\t\t}\n\n\t\treturn this;\n\t}\n\n\tevict (bypass = false) {\n\t\tif (bypass || this.size > 0) {\n\t\t\tconst item = this.first;\n\n\t\t\tdelete this.items[item.key];\n\t\t\tthis.size--;\n\n\t\t\tif (this.size === 0) {\n\t\t\t\tthis.first = null;\n\t\t\t\tthis.last = null;\n\t\t\t} else {\n\t\t\t\tthis.first = item.next;\n\t\t\t\tthis.first.prev = null;\n\t\t\t}\n\t\t}\n\n\t\treturn this;\n\t}\n\n\tget (key) {\n\t\tlet result;\n\n\t\tif (this.#has(key)) {\n\t\t\tconst item = this.items[key];\n\n\t\t\tif (this.ttl > 0 && item.expiry <= new Date().getTime()) {\n\t\t\t\tthis.delete(key);\n\t\t\t} else {\n\t\t\t\tresult = item.value;\n\t\t\t\tthis.set(key, result, true);\n\t\t\t}\n\t\t}\n\n\t\treturn result;\n\t}\n\n\tkeys () {\n\t\treturn Object.keys(this.items);\n\t}\n\n\tset (key, value, bypass = false) {\n\t\tlet item;\n\n\t\tif (bypass || this.#has(key)) {\n\t\t\titem = this.items[key];\n\t\t\titem.value = value;\n\n\t\t\tif (this.last !== item) {\n\t\t\t\tconst last = this.last,\n\t\t\t\t\tnext = item.next,\n\t\t\t\t\tprev = item.prev;\n\n\t\t\t\tif (this.first === item) {\n\t\t\t\t\tthis.first = item.next;\n\t\t\t\t}\n\n\t\t\t\titem.next = null;\n\t\t\t\titem.prev = this.last;\n\t\t\t\tlast.next = item;\n\n\t\t\t\tif (prev !== null) {\n\t\t\t\t\tprev.next = next;\n\t\t\t\t}\n\n\t\t\t\tif (next !== null) {\n\t\t\t\t\tnext.prev = prev;\n\t\t\t\t}\n\t\t\t}\n\t\t} else {\n\t\t\tif (this.max > 0 && this.size === this.max) {\n\t\t\t\tthis.evict(true);\n\t\t\t}\n\n\t\t\titem = this.items[key] = {\n\t\t\t\texpiry: this.ttl > 0 ? new Date().getTime() + this.ttl : this.ttl,\n\t\t\t\tkey: key,\n\t\t\t\tprev: this.last,\n\t\t\t\tnext: null,\n\t\t\t\tvalue\n\t\t\t};\n\n\t\t\tif (++this.size === 1) {\n\t\t\t\tthis.first = item;\n\t\t\t} else {\n\t\t\t\tthis.last.next = item;\n\t\t\t}\n\t\t}\n\n\t\tthis.last = item;\n\n\t\treturn this;\n\t}\n}\n\nexport function lru (max = 1000, ttl = 0) {\n\tif (isNaN(max) || max < 0) {\n\t\tthrow new TypeError(\"Invalid max value\");\n\t}\n\n\tif (isNaN(ttl) || ttl < 0) {\n\t\tthrow new TypeError(\"Invalid ttl value\");\n\t}\n\n\treturn new LRU(max, ttl);\n}\n"],"names":["g","f","exports","module","define","amd","globalThis","self","lru","this","LRU","constructor","max","ttl","first","items","Object","create","last","size","has","key","clear","delete","item","prev","next","evict","bypass","get","result","expiry","Date","getTime","value","set","keys","isNaN","TypeError","defineProperty"],"mappings":";;;;CAAA,SAAAA,EAAAC,GAAA,iBAAAC,SAAA,oBAAAC,OAAAF,EAAAC,SAAA,mBAAAE,QAAAA,OAAAC,IAAAD,OAAA,CAAA,WAAAH,GAAAA,GAAAD,EAAA,oBAAAM,WAAAA,WAAAN,GAAAO,MAAAC,IAAA,CAAA,EAAA,CAAA,CAAAC,MAAA,SAAAP,GAAA,aAAA,MAAMQ,EACLC,YAAaC,EAAM,EAAGC,EAAM,GAC3BJ,KAAKK,MAAQ,KACbL,KAAKM,MAAQC,OAAOC,OAAO,MAC3BR,KAAKS,KAAO,KACZT,KAAKG,IAAMA,EACXH,KAAKU,KAAO,EACZV,KAAKI,IAAMA,CACX,CAEDO,GAAMC,GACL,OAAOA,KAAOZ,KAAKM,KACnB,CAEDO,QAMC,OALAb,KAAKK,MAAQ,KACbL,KAAKM,MAAQC,OAAOC,OAAO,MAC3BR,KAAKS,KAAO,KACZT,KAAKU,KAAO,EAELV,IACP,CAEDc,OAAQF,GACP,GAAIZ,MAAKW,EAAKC,GAAM,CACnB,MAAMG,EAAOf,KAAKM,MAAMM,UAEjBZ,KAAKM,MAAMM,GAClBZ,KAAKU,OAEa,OAAdK,EAAKC,OACRD,EAAKC,KAAKC,KAAOF,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IAAM,GAAKH,KAAKU,OAASV,KAAKG,KACtCH,KAAKkB,OAAM,GAGZH,EAAOf,KAAKM,MAAMM,GAAO,CACxBU,OAAQtB,KAAKI,IAAM,GAAI,IAAImB,MAAOC,UAAYxB,KAAKI,IAAMJ,KAAKI,IAC9DQ,IAAKA,EACLI,KAAMhB,KAAKS,KACXQ,KAAM,KACNQ,SAGmB,KAAdzB,KAAKU,KACVV,KAAKK,MAAQU,EAEbf,KAAKS,KAAKQ,KAAOF,EAMnB,OAFAf,KAAKS,KAAOM,EAELf,IACP,EAaFP,EAAAM,IAVO,SAAcI,EAAM,IAAMC,EAAM,GACtC,GAAIwB,MAAMzB,IAAQA,EAAM,EACvB,MAAM,IAAI0B,UAAU,qBAGrB,GAAID,MAAMxB,IAAQA,EAAM,EACvB,MAAM,IAAIyB,UAAU,qBAGrB,OAAO,IAAI5B,EAAIE,EAAKC,EACrB,EAAAG,OAAAuB,eAAArC,EAAA,aAAA,CAAAgC,OAAA,GAAA"} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 187df51..73972ab 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,12 +1,12 @@ { "name": "tiny-lru", - "version": "9.0.3", + "version": "10.0.0", "lockfileVersion": 2, "requires": true, "packages": { "": { "name": "tiny-lru", - "version": "9.0.3", + "version": "10.0.0", "license": "BSD-3-Clause", "devDependencies": { "auto-changelog": "^2.4.0", diff --git a/package.json b/package.json index 1d15342..39f72fd 100644 --- a/package.json +++ b/package.json @@ -1,7 +1,7 @@ { "name": "tiny-lru", "description": "Tiny LRU cache for Client or Server", - "version": "9.0.3", + "version": "10.0.0", "homepage": "https://github.com/avoidwork/tiny-lru", "author": "Jason Mulligan ", "repository": { diff --git a/src/lru.js b/src/lru.js index 0dc7772..8298500 100644 --- a/src/lru.js +++ b/src/lru.js @@ -8,7 +8,7 @@ class LRU { this.ttl = ttl; } - has (key) { + #has (key) { return key in this.items; } @@ -22,7 +22,7 @@ class LRU { } delete (key) { - if (this.has(key)) { + if (this.#has(key)) { const item = this.items[key]; delete this.items[key]; @@ -70,7 +70,7 @@ class LRU { get (key) { let result; - if (this.has(key)) { + if (this.#has(key)) { const item = this.items[key]; if (this.ttl > 0 && item.expiry <= new Date().getTime()) { @@ -91,7 +91,7 @@ class LRU { set (key, value, bypass = false) { let item; - if (bypass || this.has(key)) { + if (bypass || this.#has(key)) { item = this.items[key]; item.value = value;