Comparing version 2.3.0 to 2.4.0
@@ -1,1 +0,1 @@ | ||
"use strict";var __awaiter=this&&this.__awaiter||function(t,n,e,r){return new(e||(e=Promise))((function(i,o){function u(t){try{a(r.next(t))}catch(t){o(t)}}function s(t){try{a(r.throw(t))}catch(t){o(t)}}function a(t){var n;t.done?i(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(u,s)}a((r=r.apply(t,n||[])).next())}))},__generator=this&&this.__generator||function(t,n){var e,r,i,o,u={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(e)throw new TypeError("Generator is already executing.");for(;u;)try{if(e=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return u.label++,{value:o[1],done:!1};case 5:u.label++,r=o[1],o=[0];continue;case 7:o=u.ops.pop(),u.trys.pop();continue;default:if(!(i=u.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){u=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){u.label=o[1];break}if(6===o[0]&&u.label<i[1]){u.label=i[1],i=o;break}if(i&&u.label<i[2]){u.label=i[2],u.ops.push(o);break}i[2]&&u.ops.pop(),u.trys.pop();continue}o=n.call(t,u)}catch(t){o=[6,t],r=0}finally{e=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Cachu=void 0;var Cachu=function(t){var n,e,r=this;this.set=function(t,n){return __awaiter(r,void 0,void 0,(function(){var e,r=this;return __generator(this,(function(i){return-1!==this.store.findIndex((function(n){return n[0]===t}))?[2,!1]:(this.store=this.store.filter((function(t){return Date.now()-t[2]<1e3*r.maxAge.valueOf()})),this.store.length===this.maxAmount&&(e=this.store.reduce((function(t,n){return t[2]<n[2]?t:n})),this.store.splice(this.store.findIndex((function(t){return t[0]===e[0]})),1)),this.store.push([t,n,Date.now()]),[2,!0])}))}))},this.get=function(t){return __awaiter(r,void 0,void 0,(function(){var n,e=this;return __generator(this,(function(r){return this.store=this.store.filter((function(t){return Date.now()-t[2]<1e3*e.maxAge.valueOf()})),-1===(n=this.store.findIndex((function(n){return n[0]===t})))?[2,null]:[2,this.store[n][1]]}))}))},this.view=function(t){return __awaiter(r,void 0,void 0,(function(){var n,e=this;return __generator(this,(function(r){return this.store=this.store.filter((function(n){return Date.now()-n[2]<1e3*e.maxAge.valueOf()||n[0]===t})),-1===(n=this.store.findIndex((function(n){return n[0]===t})))?[2,null]:[2,this.store[n][1]]}))}))},this.update=function(t,n){return __awaiter(r,void 0,void 0,(function(){var e;return __generator(this,(function(r){return-1===(e=this.store.findIndex((function(n){return n[0]===t})))?[2,!1]:(this.store[e]=[t,n,Date.now()],[2,!0])}))}))},this.has=function(t){return __awaiter(r,void 0,void 0,(function(){return __generator(this,(function(n){return-1===this.store.findIndex((function(n){return n[0]===t}))?[2,!1]:[2,!0]}))}))},this.purge=function(t){return __awaiter(r,void 0,void 0,(function(){var n;return __generator(this,(function(e){return-1===(n=this.store.findIndex((function(n){return n[0]===t})))?[2,!1]:(this.store.splice(n,1),[2,!0])}))}))},this.prune=function(){return __awaiter(r,void 0,void 0,(function(){var t=this;return __generator(this,(function(n){return this.store.length>0&&(this.store=this.store.filter((function(n){return Date.now()-n[2]<1e3*t.maxAge.valueOf()}))),[2,!0]}))}))},this.destroy=function(){return __awaiter(r,void 0,void 0,(function(){return __generator(this,(function(t){return this.store=[],[2,!0]}))}))},this.purgeMany=function(t){return __awaiter(r,void 0,void 0,(function(){var n,e,r;return __generator(this,(function(i){switch(i.label){case 0:n=0,e=t,i.label=1;case 1:return n<e.length?(r=e[n],[4,this.purge(r)]):[3,4];case 2:i.sent(),i.label=3;case 3:return n++,[3,1];case 4:return[2,!0]}}))}))},this.getMany=function(t){return __awaiter(r,void 0,void 0,(function(){var n,e,r,i,o;return __generator(this,(function(u){switch(u.label){case 0:n=[],e=0,r=t,u.label=1;case 1:return e<r.length?(i=r[e],[4,this.get(i)]):[3,4];case 2:null===(o=u.sent())&&void 0===o||n.push(o),u.label=3;case 3:return e++,[3,1];case 4:return[2,n]}}))}))},this.purgeManyByCondition=function(t){return __awaiter(r,void 0,void 0,(function(){return __generator(this,(function(n){return this.store=this.store.filter((function(n){return!t(n)})),[2,!0]}))}))},this.getManyByCondition=function(t){return __awaiter(r,void 0,void 0,(function(){var n,e,r,i,o;return __generator(this,(function(u){for(n=this.store.filter((function(n){return t(n)})),e=[],r=0,i=n;r<i.length;r++)o=i[r],e.push(o[1]);return[2,e]}))}))},this.getAmountOfItems=function(){return __awaiter(r,void 0,void 0,(function(){return __generator(this,(function(t){return[2,this.store.length]}))}))},this.getValuesOfItems=function(){return __awaiter(r,void 0,void 0,(function(){return __generator(this,(function(t){return 0===this.store.length?[2]:[2,this.store.map((function(t){return t[1]}))]}))}))},this.getKeysOfItems=function(){return __awaiter(r,void 0,void 0,(function(){return __generator(this,(function(t){return 0===this.store.length?[2]:[2,this.store.map((function(t){return t[0]}))]}))}))},this.each=function(t){return __awaiter(r,void 0,void 0,(function(){var n=this;return __generator(this,(function(e){return this.store.forEach((function(e){return __awaiter(n,void 0,void 0,(function(){return __generator(this,(function(n){switch(n.label){case 0:return[4,t(e)];case 1:return n.sent(),[2]}}))}))})),[2,!0]}))}))},t||(t={}),this.maxAmount=null!==(n=t.maxAmount)&&void 0!==n?n:1/0,this.maxAge=null!==(e=t.maxAge)&&void 0!==e?e:1/0,this.store=[]};exports.Cachu=Cachu; | ||
"use strict";var __awaiter=this&&this.__awaiter||function(t,n,e,r){return new(e||(e=Promise))((function(i,o){function u(t){try{a(r.next(t))}catch(t){o(t)}}function s(t){try{a(r.throw(t))}catch(t){o(t)}}function a(t){var n;t.done?i(t.value):(n=t.value,n instanceof e?n:new e((function(t){t(n)}))).then(u,s)}a((r=r.apply(t,n||[])).next())}))},__generator=this&&this.__generator||function(t,n){var e,r,i,o,u={label:0,sent:function(){if(1&i[0])throw i[1];return i[1]},trys:[],ops:[]};return o={next:s(0),throw:s(1),return:s(2)},"function"==typeof Symbol&&(o[Symbol.iterator]=function(){return this}),o;function s(o){return function(s){return function(o){if(e)throw new TypeError("Generator is already executing.");for(;u;)try{if(e=1,r&&(i=2&o[0]?r.return:o[0]?r.throw||((i=r.return)&&i.call(r),0):r.next)&&!(i=i.call(r,o[1])).done)return i;switch(r=0,i&&(o=[2&o[0],i.value]),o[0]){case 0:case 1:i=o;break;case 4:return u.label++,{value:o[1],done:!1};case 5:u.label++,r=o[1],o=[0];continue;case 7:o=u.ops.pop(),u.trys.pop();continue;default:if(!(i=u.trys,(i=i.length>0&&i[i.length-1])||6!==o[0]&&2!==o[0])){u=0;continue}if(3===o[0]&&(!i||o[1]>i[0]&&o[1]<i[3])){u.label=o[1];break}if(6===o[0]&&u.label<i[1]){u.label=i[1],i=o;break}if(i&&u.label<i[2]){u.label=i[2],u.ops.push(o);break}i[2]&&u.ops.pop(),u.trys.pop();continue}o=n.call(t,u)}catch(t){o=[6,t],r=0}finally{e=i=0}if(5&o[0])throw o[1];return{value:o[0]?o[1]:void 0,done:!0}}([o,s])}}};Object.defineProperty(exports,"__esModule",{value:!0}),exports.Cachu=void 0;var Cachu=function(t){var n,e,r=this;this.set=function(t,n){return __awaiter(r,void 0,void 0,(function(){var e,r=this;return __generator(this,(function(i){return-1!==this.store.findIndex((function(n){return n[0]===t}))?[2,!1]:(this.store=this.store.filter((function(t){return Date.now()-t[2]<1e3*r.maxAge.valueOf()})),this.store.length===this.maxAmount&&(e=this.store.reduce((function(t,n){return t[2]<n[2]?t:n})),this.store.splice(this.store.findIndex((function(t){return t[0]===e[0]})),1)),this.store.push([t,n,Date.now()]),[2,!0])}))}))},this.get=function(t){return __awaiter(r,void 0,void 0,(function(){var n,e=this;return __generator(this,(function(r){return this.store=this.store.filter((function(t){return Date.now()-t[2]<1e3*e.maxAge.valueOf()})),-1===(n=this.store.findIndex((function(n){return n[0]===t})))?[2,null]:[2,this.store[n][1]]}))}))},this.view=function(t){return __awaiter(r,void 0,void 0,(function(){var n,e=this;return __generator(this,(function(r){return this.store=this.store.filter((function(n){return Date.now()-n[2]<1e3*e.maxAge.valueOf()||n[0]===t})),-1===(n=this.store.findIndex((function(n){return n[0]===t})))?[2,null]:[2,this.store[n][1]]}))}))},this.update=function(t,n){return __awaiter(r,void 0,void 0,(function(){var e;return __generator(this,(function(r){return-1===(e=this.store.findIndex((function(n){return n[0]===t})))?[2,!1]:(this.store[e]=[t,n,Date.now()],[2,!0])}))}))},this.has=function(t){return __awaiter(r,void 0,void 0,(function(){return __generator(this,(function(n){return-1===this.store.findIndex((function(n){return n[0]===t}))?[2,!1]:[2,!0]}))}))},this.purge=function(t){return __awaiter(r,void 0,void 0,(function(){var n;return __generator(this,(function(e){return-1===(n=this.store.findIndex((function(n){return n[0]===t})))?[2,!1]:(this.store.splice(n,1),[2,!0])}))}))},this.prune=function(){return __awaiter(r,void 0,void 0,(function(){var t=this;return __generator(this,(function(n){return this.store.length>0&&(this.store=this.store.filter((function(n){return Date.now()-n[2]<1e3*t.maxAge.valueOf()}))),[2,!0]}))}))},this.destroy=function(){return __awaiter(r,void 0,void 0,(function(){return __generator(this,(function(t){return this.store=[],[2,!0]}))}))},this.purgeMany=function(t){return __awaiter(r,void 0,void 0,(function(){var n,e,r;return __generator(this,(function(i){switch(i.label){case 0:n=0,e=t,i.label=1;case 1:return n<e.length?(r=e[n],[4,this.purge(r)]):[3,4];case 2:i.sent(),i.label=3;case 3:return n++,[3,1];case 4:return[2,!0]}}))}))},this.getMany=function(t){return __awaiter(r,void 0,void 0,(function(){var n,e,r,i,o;return __generator(this,(function(u){switch(u.label){case 0:n=[],e=0,r=t,u.label=1;case 1:return e<r.length?(i=r[e],[4,this.get(i)]):[3,4];case 2:null===(o=u.sent())&&void 0===o||n.push(o),u.label=3;case 3:return e++,[3,1];case 4:return[2,n]}}))}))},this.purgeManyByCondition=function(t){return __awaiter(r,void 0,void 0,(function(){return __generator(this,(function(n){return this.store=this.store.filter((function(n){return!t(n[0],n[1],n[2])})),[2,!0]}))}))},this.getManyByCondition=function(t){return __awaiter(r,void 0,void 0,(function(){var n,e,r,i,o;return __generator(this,(function(u){for(n=this.store.filter((function(n){return t(n[0],n[1],n[2])})),e=[],r=0,i=n;r<i.length;r++)o=i[r],e.push(o[1]);return[2,e]}))}))},this.getAmountOfItems=function(){return __awaiter(r,void 0,void 0,(function(){return __generator(this,(function(t){return[2,this.store.length]}))}))},this.getValuesOfItems=function(){return __awaiter(r,void 0,void 0,(function(){return __generator(this,(function(t){return 0===this.store.length?[2]:[2,this.store.map((function(t){return t[1]}))]}))}))},this.getKeysOfItems=function(){return __awaiter(r,void 0,void 0,(function(){return __generator(this,(function(t){return 0===this.store.length?[2]:[2,this.store.map((function(t){return t[0]}))]}))}))},this.each=function(t){return __awaiter(r,void 0,void 0,(function(){var n=this;return __generator(this,(function(e){return this.store.forEach((function(e){return __awaiter(n,void 0,void 0,(function(){return __generator(this,(function(n){switch(n.label){case 0:return[4,t(e)];case 1:return n.sent(),[2]}}))}))})),[2,!0]}))}))},t||(t={}),this.maxAmount=null!==(n=t.maxAmount)&&void 0!==n?n:1/0,this.maxAge=null!==(e=t.maxAge)&&void 0!==e?e:1/0,this.store=[]};exports.Cachu=Cachu; |
{ | ||
"name": "cachu", | ||
"version": "2.3.0", | ||
"version": "2.4.0", | ||
"description": "Simple, minimalistic key-value cache.", | ||
@@ -5,0 +5,0 @@ "main": "build/index.js", |
# cachu | ||
[![npm](https://img.shields.io/npm/v/cachu)](https://www.npmjs.com/package/cachu) | ||
[![npm](https://img.shields.io/npm/dt/cachu)](https://www.npmjs.com/package/cachu) | ||
[![npm bundle size](https://img.shields.io/bundlephobia/min/cachu)](https://bundlephobia.com/package/cachu) | ||
[![GitHub last commit](https://img.shields.io/github/last-commit/azurystudios/cachu)](https://github.com/azurystudios/cachu) | ||
[![GitHub issues](https://img.shields.io/github/issues-raw/azurystudios/cachu)](https://github.com/azurystudios/cachu/issues) | ||
[![snyk vulnerabilities](https://snyk.io/test/github/azurystudios/cachu/badge.svg)](https://snyk.io/test/github/azurystudios/cachu) | ||
Simple, minimalistic key-value cache, created by [Azury](https://github.com/azurystudios). | ||
> Compatible with Node.js [v16](https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V16.md) and [v17](https://github.com/nodejs/node/blob/master/doc/changelogs/CHANGELOG_V17.md) only! | ||
#### Why should you use cachu? | ||
@@ -31,3 +40,3 @@ | ||
Recommended if you need multiple caches. | ||
Just create a new instance, it's as easy as that! | ||
@@ -73,2 +82,2 @@ ```js | ||
- [`getKeysOfItems()`](https://github.com/azurystudios/cachu/wiki/features#get-keys-of-items) | ||
- [`each()`](https://github.com/azurystudios/cachu/wiki/features#get-keys-of-items) | ||
- [`each(action)`](https://github.com/azurystudios/cachu/wiki/features#each) |
@@ -25,3 +25,3 @@ interface Configuration { | ||
/** | ||
* **Get an Item** | ||
* **Get Item** | ||
* | ||
@@ -33,3 +33,3 @@ * Get the content of an existing item. | ||
/** | ||
* **View a Item** | ||
* **View Item** | ||
* | ||
@@ -41,3 +41,3 @@ * Get the content of an existing item without removing any overaged items or without returning `null` if it's overaged. | ||
/** | ||
* **Update a Item** | ||
* **Update Item** | ||
* | ||
@@ -50,3 +50,3 @@ * Update the content of an existing item. | ||
/** | ||
* **Has a Item** | ||
* **Has Item** | ||
* | ||
@@ -58,3 +58,3 @@ * Check if the cache has an item with the specified key. | ||
/** | ||
* **Purge a Item** | ||
* **Purge Item** | ||
* | ||
@@ -78,3 +78,3 @@ * Delete the item with the specified key. | ||
/** | ||
* **Purge Many Items** | ||
* **Purge Multiple Items** | ||
* | ||
@@ -86,3 +86,3 @@ * Delete multiple items by their keys. | ||
/** | ||
* **Get Many Items** | ||
* **Get Multiple Items** | ||
* | ||
@@ -94,3 +94,3 @@ * Get multiple items by their keys. | ||
/** | ||
* **Purge Many Items by a Condition** | ||
* **Purge Multiple Items Conditionally** | ||
* | ||
@@ -102,3 +102,3 @@ * Delete multiple items by a specific condition. | ||
/** | ||
* **Get Multiple Items by a Condition** | ||
* **Get Multiple Items Conditionally** | ||
* | ||
@@ -110,3 +110,3 @@ * Delete multiple items by a specific condition. | ||
/** | ||
* **Get Amount of Items** | ||
* **Get Amount Of Items** | ||
* | ||
@@ -117,3 +117,3 @@ * Get the amount of items the cache has. | ||
/** | ||
* **Get Values of Items** | ||
* **Get Values Of Items** | ||
* | ||
@@ -124,3 +124,3 @@ * Get an array of all the item values. | ||
/** | ||
* **Get Keys of Items** | ||
* **Get Keys Of Items** | ||
* | ||
@@ -131,3 +131,3 @@ * Get an array of all item keys. | ||
/** | ||
* **Execute an Action on Each Item** | ||
* **Iterate Over Items** | ||
* | ||
@@ -134,0 +134,0 @@ * Executes a specific function on each item. |
25220
82