Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

cachu

Package Overview
Dependencies
Maintainers
1
Versions
61
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

cachu - npm Package Compare versions

Comparing version 2.4.0 to 2.4.1

2

build/index.js

@@ -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[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;
"use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.Cachu=void 0;class Cachu{constructor(t){this.set=async(t,s)=>{if(-1!==this.store.findIndex((s=>s[0]===t)))return!1;if(this.store=this.store.filter((t=>Date.now()-t[2]<1e3*this.maxAge.valueOf())),this.store.length===this.maxAmount){const t=this.store.reduce(((t,s)=>t[2]<s[2]?t:s));this.store.splice(this.store.findIndex((s=>s[0]===t[0])),1)}return this.store.push([t,s,Date.now()]),!0},this.get=async t=>{this.store=this.store.filter((t=>Date.now()-t[2]<1e3*this.maxAge.valueOf()));const s=this.store.findIndex((s=>s[0]===t));return-1===s?null:this.store[s][1]},this.view=async t=>{this.store=this.store.filter((s=>Date.now()-s[2]<1e3*this.maxAge.valueOf()||s[0]===t));const s=this.store.findIndex((s=>s[0]===t));return-1===s?null:this.store[s][1]},this.update=async(t,s)=>{const e=this.store.findIndex((s=>s[0]===t));return-1!==e&&(this.store[e]=[t,s,Date.now()],!0)},this.has=async t=>-1!==this.store.findIndex((s=>s[0]===t)),this.purge=async t=>{const s=this.store.findIndex((s=>s[0]===t));return-1!==s&&(this.store.splice(s,1),!0)},this.prune=async()=>(this.store.length>0&&(this.store=this.store.filter((t=>Date.now()-t[2]<1e3*this.maxAge.valueOf()))),!0),this.destroy=async()=>(this.store=[],!0),this.purgeMany=async t=>{for(const s of t)await this.purge(s);return!0},this.getMany=async t=>{const s=[];for(const e of t){const t=await this.get(e);null===t&&void 0===t||s.push(t)}return s},this.purgeManyByCondition=async t=>(this.store=this.store.filter((s=>!t(s[0],s[1],s[2]))),!0),this.getManyByCondition=async t=>{const s=this.store.filter((s=>t(s[0],s[1],s[2]))),e=[];for(const t of s)e.push(t[1]);return e},this.getAmountOfItems=async()=>this.store.length,this.getValuesOfItems=async()=>{if(0!==this.store.length)return this.store.map((t=>t[1]))},this.getKeysOfItems=async()=>{if(0!==this.store.length)return this.store.map((t=>t[0]))},this.each=async t=>(this.store.forEach((async s=>{await t(s)})),!0),t||(t={}),this.maxAmount=t.maxAmount??1/0,this.maxAge=t.maxAge??1/0,this.store=[]}}exports.Cachu=Cachu;
{
"name": "cachu",
"version": "2.4.0",
"version": "2.4.1",
"description": "Simple, minimalistic key-value cache.",

@@ -9,5 +9,6 @@ "main": "build/index.js",

"build": "tsc -w",
"release:patch": "node minify.mjs && npm version patch && npm publish",
"release:minor": "node minify.mjs && npm version minor && npm publish",
"release:major": "node minify.mjs && npm version major && npm publish",
"minify": "node minify.mjs",
"publish:patch": "npm run minify && npm version patch && npm publish",
"publish:minor": "npm run minify && npm version minor && npm publish",
"publish:major": "npm run minify && npm version major && npm publish",
"test": "jest --detectOpenHandles"

@@ -14,0 +15,0 @@ },

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc