From b230fc8e52baf81a5fbb371a76e079e45c3702fd Mon Sep 17 00:00:00 2001 From: Jason Mulligan Date: Wed, 30 Jan 2019 16:14:00 -0500 Subject: [PATCH] Rebuilding so version tag is updated everywhere --- lib/tiny-lru.es5.js | 2 +- lib/tiny-lru.js | 2 +- lib/tiny-lru.min.js | 2 +- lib/tiny-lru.min.js.map | 2 +- package-lock.json | 2 +- 5 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/tiny-lru.es5.js b/lib/tiny-lru.es5.js index c060e0d..6b3be9f 100644 --- a/lib/tiny-lru.es5.js +++ b/lib/tiny-lru.es5.js @@ -10,7 +10,7 @@ function _classCallCheck(instance, Constructor) { if (!(instance instanceof Cons * @author Jason Mulligan * @copyright 2019 * @license BSD-3-Clause - * @version 6.0.0 + * @version 6.0.1 */ (function (global) { diff --git a/lib/tiny-lru.js b/lib/tiny-lru.js index 82f0a99..5304773 100644 --- a/lib/tiny-lru.js +++ b/lib/tiny-lru.js @@ -4,7 +4,7 @@ * @author Jason Mulligan * @copyright 2019 * @license BSD-3-Clause - * @version 6.0.0 + * @version 6.0.1 */ "use strict"; diff --git a/lib/tiny-lru.min.js b/lib/tiny-lru.min.js index 8378bd0..1fa40a2 100644 --- a/lib/tiny-lru.min.js +++ b/lib/tiny-lru.min.js @@ -4,7 +4,7 @@ * @author Jason Mulligan * @copyright 2019 * @license BSD-3-Clause - * @version 6.0.0 + * @version 6.0.1 */(function(a){function b(a=1e3,b=0){if(isNaN(a)||0>a)throw new TypeError("Invalid max value");if(isNaN(b)||0>b)throw new TypeError("Invalid ttl value");return new c(a,b)}// Node, AMD & window supported class c{constructor(a=0,b=0){this.first=null,this.items={},this.last=null,this.max=a,this.size=0,this.ttl=b}has(a){return a in this.items}clear(){return this.first=null,this.items={},this.last=null,this.size=0,this}delete(a){if(this.has(a)){const b=this.items[a];delete this.items[a],this.size--,null!==b.prev&&(b.prev.next=b.next),null!==b.next&&(b.next.prev=b.prev),this.first===b&&(this.first=b.next),this.last===b&&(this.last=b.prev)}return this}evict(){const a=this.first;return delete this.items[a.key],this.first=a.next,this.first.prev=null,this.size--,this}get(a){let b;if(this.has(a)){const c=this.items[a];0b):a.lru=b:module.exports=b})("undefined"==typeof window?global:window); //# sourceMappingURL=tiny-lru.min.js.map \ No newline at end of file diff --git a/lib/tiny-lru.min.js.map b/lib/tiny-lru.min.js.map index f6620d6..44a4a5b 100644 --- a/lib/tiny-lru.min.js.map +++ b/lib/tiny-lru.min.js.map @@ -1 +1 @@ -{"version":3,"sources":["tiny-lru.js"],"names":["global","factory","max","ttl","isNaN","TypeError","LRU","constructor","first","items","last","size","has","key","clear","delete","item","prev","next","evict","get","result","expiry","Date","getTime","value","set","keys","Object","bypass","exports","define","amd","lru","module","window"],"mappings":"AAAA;;;;;;;GAUC,UAAUA,CAAV,CAAkB,CA0IlB,QAASC,EAAT,CAAkBC,EAAM,GAAxB,CAA8BC,EAAM,CAApC,CAAuC,CACtC,GAAIC,MAAMF,CAAN,GAAoB,CAAN,EAAlB,CACC,KAAM,IAAIG,UAAJ,CAAc,mBAAd,CAAN,CAGD,GAAID,MAAMD,CAAN,GAAoB,CAAN,EAAlB,CACC,KAAM,IAAIE,UAAJ,CAAc,mBAAd,CAAN,CAGD,MAAO,IAAIC,EAAJ,CAAQJ,CAAR,CAAaC,CAAb,CACP,CAED;AApJA,KAAMG,EAAI,CACTC,YAAaL,EAAM,CAAnB,CAAsBC,EAAM,CAA5B,CAA+B,CAC9B,KAAKK,KAAL,CAAa,IADiB,CAE9B,KAAKC,KAAL,CAAa,EAFiB,CAG9B,KAAKC,IAAL,CAAY,IAHkB,CAI9B,KAAKR,GAAL,CAAWA,CAJmB,CAK9B,KAAKS,IAAL,CAAY,CALkB,CAM9B,KAAKR,GAAL,CAAWA,CACX,CAEDS,IAAKC,CAAL,CAAU,CACT,MAAOA,KAAO,MAAKJ,KACnB,CAEDK,OAAS,CAMR,MALA,MAAKN,KAAL,CAAa,IAKb,CAJA,KAAKC,KAAL,C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,CAEZ,CAAO,IACP,CArIQ,CAqJa,WAAnB,QAAOc,QAvJO,CAyJW,UAAlB,QAAOC,OAAP,EAA+C,IAAK,EAApB,UAAOC,GAzJhC,CA0JjBD,OAAO,IAAM9B,CAAb,CA1JiB,CA4JjBD,EAAOiC,GAAP,CAAahC,CA5JI,CAwJjBiC,OAAOJ,OAAP,CAAiB7B,CAMlB,CA9JA,EA8JmB,WAAlB,QAAOkC,OAAP,CAAyCnC,MAAzC,CAAgCmC,MA9JjC,C","file":"unknown","sourcesContent":["/**\r\n * Tiny LRU cache for Client or Server\r\n *\r\n * @author Jason Mulligan \r\n * @copyright 2019\r\n * @license BSD-3-Clause\r\n * @version 6.0.0\r\n */\r\n\r\n\r\n(function (global) {\r\n\r\n\tclass LRU {\r\n\t\tconstructor (max = 0, ttl = 0) {\r\n\t\t\tthis.first = null;\r\n\t\t\tthis.items = {};\r\n\t\t\tthis.last = null;\r\n\t\t\tthis.max = max;\r\n\t\t\tthis.size = 0;\r\n\t\t\tthis.ttl = ttl;\r\n\t\t}\r\n\r\n\t\thas (key) {\r\n\t\t\treturn key in this.items;\r\n\t\t}\r\n\r\n\t\tclear () {\r\n\t\t\tthis.first = null;\r\n\t\t\tthis.items = {};\r\n\t\t\tthis.last = null;\r\n\t\t\tthis.size = 0;\r\n\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tdelete (key) {\r\n\t\t\tif (this.has(key)) {\r\n\t\t\t\tconst item = this.items[key];\r\n\r\n\t\t\t\tdelete this.items[key];\r\n\t\t\t\tthis.size--;\r\n\r\n\t\t\t\tif (item.prev !== null) {\r\n\t\t\t\t\titem.prev.next = item.next;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (item.next !== null) {\r\n\t\t\t\t\titem.next.prev = item.prev;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (this.first === item) {\r\n\t\t\t\t\tthis.first = item.next;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (this.last === item) {\r\n\t\t\t\t\tthis.last = item.prev;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tevict () {\r\n\t\t\tconst item = this.first;\r\n\r\n\t\t\tdelete this.items[item.key];\r\n\t\t\tthis.first = item.next;\r\n\t\t\tthis.first.prev = null;\r\n\t\t\tthis.size--;\r\n\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tget (key) {\r\n\t\t\tlet result;\r\n\r\n\t\t\tif (this.has(key)) {\r\n\t\t\t\tconst item = this.items[key];\r\n\r\n\t\t\t\tif (this.ttl > 0 && item.expiry <= new Date().getTime()) {\r\n\t\t\t\t\tthis.delete(key);\r\n\t\t\t\t} else {\r\n\t\t\t\t\tresult = item.value;\r\n\t\t\t\t\tthis.set(key, result, true);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\treturn result;\r\n\t\t}\r\n\r\n\t\tkeys () {\r\n\t\t\treturn Object.keys(this.items);\r\n\t\t}\r\n\r\n\t\tset (key, value, bypass = false) {\r\n\t\t\tlet item;\r\n\r\n\t\t\tif (bypass || this.has(key)) {\r\n\t\t\t\titem = this.items[key];\r\n\t\t\t\titem.value = value;\r\n\r\n\t\t\t\tif (this.last !== item) {\r\n\t\t\t\t\tconst last = this.last,\r\n\t\t\t\t\t\tnext = item.next,\r\n\t\t\t\t\t\tprev = item.prev;\r\n\r\n\t\t\t\t\tif (this.first === item) {\r\n\t\t\t\t\t\tthis.first = item.next;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\titem.next = null;\r\n\t\t\t\t\titem.prev = this.last;\r\n\t\t\t\t\tlast.next = item;\r\n\r\n\t\t\t\t\tif (prev !== null) {\r\n\t\t\t\t\t\tprev.next = next;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tif (next !== null) {\r\n\t\t\t\t\t\tnext.prev = prev;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t} else {\r\n\t\t\t\tif (this.max > 0 && this.size === this.max) {\r\n\t\t\t\t\tthis.evict();\r\n\t\t\t\t}\r\n\r\n\t\t\t\titem = this.items[key] = {\r\n\t\t\t\t\texpiry: this.ttl > 0 ? new Date().getTime() + this.ttl : this.ttl,\r\n\t\t\t\t\tkey: key,\r\n\t\t\t\t\tprev: this.last,\r\n\t\t\t\t\tnext: null,\r\n\t\t\t\t\tvalue\r\n\t\t\t\t};\r\n\r\n\t\t\t\tif (++this.size === 1) {\r\n\t\t\t\t\tthis.first = item;\r\n\t\t\t\t} else {\r\n\t\t\t\t\tthis.last.next = item;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tthis.last = item;\r\n\r\n\t\t\treturn this;\r\n\t\t}\r\n\t}\r\n\r\n\tfunction factory (max = 1000, ttl = 0) {\r\n\t\tif (isNaN(max) || max < 0) {\r\n\t\t\tthrow new TypeError(\"Invalid max value\");\r\n\t\t}\r\n\r\n\t\tif (isNaN(ttl) || ttl < 0) {\r\n\t\t\tthrow new TypeError(\"Invalid ttl value\");\r\n\t\t}\r\n\r\n\t\treturn new LRU(max, ttl);\r\n\t}\r\n\r\n\t// Node, AMD & window supported\r\n\tif (typeof exports !== \"undefined\") {\r\n\t\tmodule.exports = factory;\r\n\t} else if (typeof define === \"function\" && define.amd !== void 0) {\r\n\t\tdefine(() => factory);\r\n\t} else {\r\n\t\tglobal.lru = factory;\r\n\t}\r\n}(typeof window !== \"undefined\" ? window : global));\r\n"]} \ No newline at end of file +{"version":3,"sources":["tiny-lru.js"],"names":["global","factory","max","ttl","isNaN","TypeError","LRU","constructor","first","items","last","size","has","key","clear","delete","item","prev","next","evict","get","result","expiry","Date","getTime","value","set","keys","Object","bypass","exports","define","amd","lru","module","window"],"mappings":"AAAA;;;;;;;GAUC,UAAUA,CAAV,CAAkB,CA0IlB,QAASC,EAAT,CAAkBC,EAAM,GAAxB,CAA8BC,EAAM,CAApC,CAAuC,CACtC,GAAIC,MAAMF,CAAN,GAAoB,CAAN,EAAlB,CACC,KA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yCE,KAAKN,IAAL,CAAUQ,IAAV,CAAiBF,CAzCnB,KAIC,IAHAA,EAAO,KAAKP,KAAL,CAAWI,CAAX,CAGP,CAFAG,EAAKS,KAAL,CAAaA,CAEb,CAAI,KAAKf,IAAL,GAAcM,CAAlB,CAAwB,CACvB,KAAMN,GAAO,KAAKA,IAAlB,CACCQ,EAAOF,EAAKE,IADb,CAECD,EAAOD,EAAKC,IAFb,CAII,KAAKT,KAAL,GAAeQ,CALI,GAMtB,KAAKR,KAAL,CAAaQ,EAAKE,IANI,EASvBF,EAAKE,IAAL,CAAY,IATW,CAUvBF,EAAKC,IAAL,CAAY,KAAKP,IAVM,CAWvBA,EAAKQ,IAAL,CAAYF,CAXW,CAaV,IAAT,IAbmB,GActBC,EAAKC,IAAL,CAAYA,CAdU,EAiBV,IAAT,IAjBmB,GAkBtBA,EAAKD,IAAL,CAAYA,CAlBU,CAoBvB,CAuBF,MAFA,MAAKP,IAAL,CAAYM,CAEZ,CAAO,IACP,CArIQ,CAqJa,WAAnB,QAAOc,QAvJO,CAyJW,UAAlB,QAAOC,OAAP,EAA+C,IAAK,EAApB,UAAOC,GAzJhC,CA0JjBD,OAAO,IAAM9B,CAAb,CA1JiB,CA4JjBD,EAAOiC,GAAP,CAAahC,CA5JI,CAwJjBiC,OAAOJ,OAAP,CAAiB7B,CAMlB,CA9JA,EA8JmB,WAAlB,QAAOkC,OAAP,CAAyCnC,MAAzC,CAAgCmC,MA9JjC,C","file":"unknown","sourcesContent":["/**\r\n * Tiny LRU cache for Client or Server\r\n *\r\n * @author Jason Mulligan \r\n * @copyright 2019\r\n * @license BSD-3-Clause\r\n * @version 6.0.1\r\n */\r\n\r\n\r\n(function (global) {\r\n\r\n\tclass LRU {\r\n\t\tconstructor (max = 0, ttl = 0) {\r\n\t\t\tthis.first = null;\r\n\t\t\tthis.items = {};\r\n\t\t\tthis.last = null;\r\n\t\t\tthis.max = max;\r\n\t\t\tthis.size = 0;\r\n\t\t\tthis.ttl = ttl;\r\n\t\t}\r\n\r\n\t\thas (key) {\r\n\t\t\treturn key in this.items;\r\n\t\t}\r\n\r\n\t\tclear () {\r\n\t\t\tthis.first = null;\r\n\t\t\tthis.items = {};\r\n\t\t\tthis.last = null;\r\n\t\t\tthis.size = 0;\r\n\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tdelete (key) {\r\n\t\t\tif (this.has(key)) {\r\n\t\t\t\tconst item = this.items[key];\r\n\r\n\t\t\t\tdelete this.items[key];\r\n\t\t\t\tthis.size--;\r\n\r\n\t\t\t\tif (item.prev !== null) {\r\n\t\t\t\t\titem.prev.next = item.next;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (item.next !== null) {\r\n\t\t\t\t\titem.next.prev = item.prev;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (this.first === item) {\r\n\t\t\t\t\tthis.first = item.next;\r\n\t\t\t\t}\r\n\r\n\t\t\t\tif (this.last === item) {\r\n\t\t\t\t\tthis.last = item.prev;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tevict () {\r\n\t\t\tconst item = this.first;\r\n\r\n\t\t\tdelete this.items[item.key];\r\n\t\t\tthis.first = item.next;\r\n\t\t\tthis.first.prev = null;\r\n\t\t\tthis.size--;\r\n\r\n\t\t\treturn this;\r\n\t\t}\r\n\r\n\t\tget (key) {\r\n\t\t\tlet result;\r\n\r\n\t\t\tif (this.has(key)) {\r\n\t\t\t\tconst item = this.items[key];\r\n\r\n\t\t\t\tif (this.ttl > 0 && item.expiry <= new Date().getTime()) {\r\n\t\t\t\t\tthis.delete(key);\r\n\t\t\t\t} else {\r\n\t\t\t\t\tresult = item.value;\r\n\t\t\t\t\tthis.set(key, result, true);\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\treturn result;\r\n\t\t}\r\n\r\n\t\tkeys () {\r\n\t\t\treturn Object.keys(this.items);\r\n\t\t}\r\n\r\n\t\tset (key, value, bypass = false) {\r\n\t\t\tlet item;\r\n\r\n\t\t\tif (bypass || this.has(key)) {\r\n\t\t\t\titem = this.items[key];\r\n\t\t\t\titem.value = value;\r\n\r\n\t\t\t\tif (this.last !== item) {\r\n\t\t\t\t\tconst last = this.last,\r\n\t\t\t\t\t\tnext = item.next,\r\n\t\t\t\t\t\tprev = item.prev;\r\n\r\n\t\t\t\t\tif (this.first === item) {\r\n\t\t\t\t\t\tthis.first = item.next;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\titem.next = null;\r\n\t\t\t\t\titem.prev = this.last;\r\n\t\t\t\t\tlast.next = item;\r\n\r\n\t\t\t\t\tif (prev !== null) {\r\n\t\t\t\t\t\tprev.next = next;\r\n\t\t\t\t\t}\r\n\r\n\t\t\t\t\tif (next !== null) {\r\n\t\t\t\t\t\tnext.prev = prev;\r\n\t\t\t\t\t}\r\n\t\t\t\t}\r\n\t\t\t} else {\r\n\t\t\t\tif (this.max > 0 && this.size === this.max) {\r\n\t\t\t\t\tthis.evict();\r\n\t\t\t\t}\r\n\r\n\t\t\t\titem = this.items[key] = {\r\n\t\t\t\t\texpiry: this.ttl > 0 ? new Date().getTime() + this.ttl : this.ttl,\r\n\t\t\t\t\tkey: key,\r\n\t\t\t\t\tprev: this.last,\r\n\t\t\t\t\tnext: null,\r\n\t\t\t\t\tvalue\r\n\t\t\t\t};\r\n\r\n\t\t\t\tif (++this.size === 1) {\r\n\t\t\t\t\tthis.first = item;\r\n\t\t\t\t} else {\r\n\t\t\t\t\tthis.last.next = item;\r\n\t\t\t\t}\r\n\t\t\t}\r\n\r\n\t\t\tthis.last = item;\r\n\r\n\t\t\treturn this;\r\n\t\t}\r\n\t}\r\n\r\n\tfunction factory (max = 1000, ttl = 0) {\r\n\t\tif (isNaN(max) || max < 0) {\r\n\t\t\tthrow new TypeError(\"Invalid max value\");\r\n\t\t}\r\n\r\n\t\tif (isNaN(ttl) || ttl < 0) {\r\n\t\t\tthrow new TypeError(\"Invalid ttl value\");\r\n\t\t}\r\n\r\n\t\treturn new LRU(max, ttl);\r\n\t}\r\n\r\n\t// Node, AMD & window supported\r\n\tif (typeof exports !== \"undefined\") {\r\n\t\tmodule.exports = factory;\r\n\t} else if (typeof define === \"function\" && define.amd !== void 0) {\r\n\t\tdefine(() => factory);\r\n\t} else {\r\n\t\tglobal.lru = factory;\r\n\t}\r\n}(typeof window !== \"undefined\" ? window : global));\r\n"]} \ No newline at end of file diff --git a/package-lock.json b/package-lock.json index 148f801..41cd7a4 100644 --- a/package-lock.json +++ b/package-lock.json @@ -1,6 +1,6 @@ { "name": "tiny-lru", - "version": "6.0.0", + "version": "6.0.1", "lockfileVersion": 1, "requires": true, "dependencies": {