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 5.2.0-canary.1 to 5.2.0-canary.2

2

dist/index.js

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

var S=Object.create;var x=Object.defineProperty;var O=Object.getOwnPropertyDescriptor;var R=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,E=Object.prototype.hasOwnProperty;var G=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),U=(n,e)=>{for(var a in e)x(n,a,{get:e[a],enumerable:!0})},v=(n,e,a,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let d of R(e))!E.call(n,d)&&d!==a&&x(n,d,{get:()=>e[d],enumerable:!(i=O(e,d))||i.enumerable});return n};var L=(n,e,a)=>(a=n!=null?S(C(n)):{},v(e||!n||!n.__esModule?x(a,"default",{value:n,enumerable:!0}):a,n)),N=n=>v(x({},"__esModule",{value:!0}),n);var D=G((ie,b)=>{var f=1e3,y=f*60,m=y*60,u=m*24,B=u*7,F=u*365.25;b.exports=function(n,e){e=e||{};var a=typeof n;if(a==="string"&&n.length>0)return H(n);if(a==="number"&&isFinite(n))return e.long?K(n):I(n);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(n))};function H(n){if(n=String(n),!(n.length>100)){var e=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(n);if(!!e){var a=parseFloat(e[1]),i=(e[2]||"ms").toLowerCase();switch(i){case"years":case"year":case"yrs":case"yr":case"y":return a*F;case"weeks":case"week":case"w":return a*B;case"days":case"day":case"d":return a*u;case"hours":case"hour":case"hrs":case"hr":case"h":return a*m;case"minutes":case"minute":case"mins":case"min":case"m":return a*y;case"seconds":case"second":case"secs":case"sec":case"s":return a*f;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return a;default:return}}}}function I(n){var e=Math.abs(n);return e>=u?Math.round(n/u)+"d":e>=m?Math.round(n/m)+"h":e>=y?Math.round(n/y)+"m":e>=f?Math.round(n/f)+"s":n+"ms"}function K(n){var e=Math.abs(n);return e>=u?w(n,e,u,"day"):e>=m?w(n,e,m,"hour"):e>=y?w(n,e,y,"minute"):e>=f?w(n,e,f,"second"):n+" ms"}function w(n,e,a,i){var d=e>=a*1.5;return Math.round(n/a)+" "+i+(d?"s":"")}});var _={};U(_,{MemoryCache:()=>z});module.exports=N(_);var M=L(D()),V=(n={})=>{let e=new Map,a={},i,d=typeof n.maxAge=="number"?n.maxAge*1e3:typeof n.maxAge=="string"?(0,M.default)(n.maxAge):6e5,l=n.maxAmount??1e4,h=async()=>{e.forEach(async(t,r)=>{Date.now()-t.age>d&&e.delete(r)})},A=async()=>{let t=0,r=0;e.forEach(async(s,o)=>{s.age>t&&(t=s.age,r=o)}),e.delete(r)};return{set:async(t,r,s)=>{if(a.set&&await a.set(t,r,s),e.has(t))return;d!==1/0&&await h(),e.size>l&&await A();let o={value:r,age:Date.now(),...typeof s=="string"?{maxAge:(0,M.default)(s)}:typeof s=="number"&&{maxAge:s*1e3}};return e.set(t,o),i={key:t,...o},{key:t,...o}},setMany:async t=>{a.setMany&&await a.setMany(t),d!==1/0&&await h();let r=[];for(let s of t){let o=s[0],c=s[1],g=s[2];if(e.has(o)){r.push(void 0);continue}let p={value:c,age:Date.now(),...typeof g=="string"?{maxAge:(0,M.default)(g)}:typeof g=="number"&&{maxAge:g*1e3}};e.size>l&&await A(),e.set(o,p),i={key:o,...p},r.push({key:o,...p})}return r},get:async(t,r={})=>{a.get&&await a.get(t,r);let s=e.get(t);if(!!s){if(r.validate!==!1&&(s.maxAge?Date.now()-s.age>s.maxAge:Date.now()-s.age>d)){e.delete(t);return}return r.delete&&e.delete(t),{key:t,...s}}},getMany:async(t,r={})=>{a.getMany&&await a.getMany(t,r);let s=[];for(let o of t){let c=e.get(o);if(!c){s.push(void 0);continue}if(r.validate!==!1&&(c.maxAge?Date.now()-c.age>c.maxAge:Date.now()-c.age>d)){e.delete(o),s.push(void 0);continue}r.delete&&e.delete(o),s.push({key:o,...c})}return r.reverse?s.reverse():s},update:async(t,r,s)=>{a.update&&await a.update(t,r,s??{});let o=e.get(t);if(!o)return;let c={value:r,age:s&&s.updateAge?Date.now():o.age,...o.maxAge&&{maxAge:o.maxAge}};e.set(t,c),i={key:t,...c}},updateMany:async(t,r)=>{a.updateMany&&await a.updateMany(t,r??{});for(let s of t){let o=e.get(s[0]);if(!o)return;let c={value:s[1],age:r&&r.updateAge?Date.now():o.age,...o.maxAge&&{maxAge:o.maxAge}};e.set(s[0],c),i={key:s[0],...c}}},delete:async t=>{a.delete&&await a.delete(t),e.delete(t)},deleteMany:async t=>{a.deleteMany&&await a.deleteMany(t),t.length===0&&e.clear();for(let r of t)e.delete(r)},has:async t=>(a.has&&await a.has(t),e.has(t)),size:async()=>(a.size&&await a.size(),e.size),keys:async()=>(a.keys&&await a.keys(),[...e.keys()]),values:async()=>{a.values&&await a.values();let t=[];for(let r of[...e.values()])t.push(r.value);return t},clear:async()=>(a.clear&&await a.clear(),await h()),memory:async()=>{a.memory&&await a.memory();let t=[...e.keys()].toString()+[...e.values()].toString(),r=Buffer.from(t);return Buffer.byteLength(r)},recent:async()=>(a.recent&&await a.recent(),i),maxAge:async t=>(a.maxAge&&await a.maxAge(t),t&&(d=typeof t=="number"?t*1e3:typeof t=="string"?(0,M.default)(t):6e5,await h()),d),maxAmount:async t=>(a.maxAmount&&await a.maxAmount(t),t&&(l=t??1e4,await h()),l),newest:async()=>{if(e.size===0)return;let t=0,r;return e.forEach(async(s,o)=>{s.age>t&&(t=s.age,r={key:o,value:s.value,age:s.age,...s.maxAge&&{maxAge:s.maxAge}})}),r},oldest:async()=>{if(e.size===0)return;let t=0,r;return e.forEach(async(s,o)=>{(t===0||s.age<t)&&(t=s.age,r={key:o,value:s.value,age:s.age,...s.maxAge&&{maxAge:s.maxAge}})}),r},on:async(t,r)=>{a[t]=r}}},z=V;
var S=Object.create;var p=Object.defineProperty;var R=Object.getOwnPropertyDescriptor;var O=Object.getOwnPropertyNames;var C=Object.getPrototypeOf,E=Object.prototype.hasOwnProperty;var G=(n,e)=>()=>(e||n((e={exports:{}}).exports,e),e.exports),U=(n,e)=>{for(var a in e)p(n,a,{get:e[a],enumerable:!0})},v=(n,e,a,i)=>{if(e&&typeof e=="object"||typeof e=="function")for(let d of O(e))!E.call(n,d)&&d!==a&&p(n,d,{get:()=>e[d],enumerable:!(i=R(e,d))||i.enumerable});return n};var k=(n,e,a)=>(a=n!=null?S(C(n)):{},v(e||!n||!n.__esModule?p(a,"default",{value:n,enumerable:!0}):a,n)),L=n=>v(p({},"__esModule",{value:!0}),n);var b=G((ue,D)=>{var f=1e3,y=f*60,m=y*60,u=m*24,N=u*7,B=u*365.25;D.exports=function(n,e){e=e||{};var a=typeof n;if(a==="string"&&n.length>0)return F(n);if(a==="number"&&isFinite(n))return e.long?I(n):H(n);throw new Error("val is not a non-empty string or a valid number. val="+JSON.stringify(n))};function F(n){if(n=String(n),!(n.length>100)){var e=/^(-?(?:\d+)?\.?\d+) *(milliseconds?|msecs?|ms|seconds?|secs?|s|minutes?|mins?|m|hours?|hrs?|h|days?|d|weeks?|w|years?|yrs?|y)?$/i.exec(n);if(!!e){var a=parseFloat(e[1]),i=(e[2]||"ms").toLowerCase();switch(i){case"years":case"year":case"yrs":case"yr":case"y":return a*B;case"weeks":case"week":case"w":return a*N;case"days":case"day":case"d":return a*u;case"hours":case"hour":case"hrs":case"hr":case"h":return a*m;case"minutes":case"minute":case"mins":case"min":case"m":return a*y;case"seconds":case"second":case"secs":case"sec":case"s":return a*f;case"milliseconds":case"millisecond":case"msecs":case"msec":case"ms":return a;default:return}}}}function H(n){var e=Math.abs(n);return e>=u?Math.round(n/u)+"d":e>=m?Math.round(n/m)+"h":e>=y?Math.round(n/y)+"m":e>=f?Math.round(n/f)+"s":n+"ms"}function I(n){var e=Math.abs(n);return e>=u?x(n,e,u,"day"):e>=m?x(n,e,m,"hour"):e>=y?x(n,e,y,"minute"):e>=f?x(n,e,f,"second"):n+" ms"}function x(n,e,a,i){var d=e>=a*1.5;return Math.round(n/a)+" "+i+(d?"s":"")}});var V={};U(V,{MemoryCache:()=>z});module.exports=L(V);var M=k(b()),K=(n={})=>{let e=new Map,a={},i,d=typeof n.maxAge=="number"?n.maxAge*1e3:typeof n.maxAge=="string"?(0,M.default)(n.maxAge):6e5,l=n.maxAmount??1e4,h=async()=>{e.forEach(async(t,r)=>{Date.now()-t.age>d&&e.delete(r)})},A=async()=>{let t=0,r=0;e.forEach(async(s,o)=>{s.age>t&&(t=s.age,r=o)}),e.delete(r)};return{set:async(t,r,s)=>{if(a.set&&await a.set(t,r,s),e.has(t))return;d!==1/0&&await h(),e.size>l&&await A();let o={value:r,age:Date.now(),...typeof s=="string"?{maxAge:(0,M.default)(s)}:typeof s=="number"&&{maxAge:s*1e3}};return e.set(t,o),i={key:t,...o},{key:t,...o}},setMany:async t=>{a.setMany&&await a.setMany(t),d!==1/0&&await h();let r=[];for(let s of t){let o=s[0],c=s[1],g=s[2];if(e.has(o)){r.push(void 0);continue}let w={value:c,age:Date.now(),...typeof g=="string"?{maxAge:(0,M.default)(g)}:typeof g=="number"&&{maxAge:g*1e3}};e.size>l&&await A(),e.set(o,w),i={key:o,...w},r.push({key:o,...w})}return r},get:async(t,r={})=>{a.get&&await a.get(t,r);let s=e.get(t);if(!!s){if(r.validate!==!1&&(s.maxAge?Date.now()-s.age>s.maxAge:Date.now()-s.age>d)){e.delete(t);return}return r.delete&&e.delete(t),{key:t,...s}}},getMany:async(t,r={})=>{a.getMany&&await a.getMany(t,r);let s=[];for(let o of t){let c=e.get(o);if(!c){s.push(void 0);continue}if(r.validate!==!1&&(c.maxAge?Date.now()-c.age>c.maxAge:Date.now()-c.age>d)){e.delete(o),s.push(void 0);continue}r.delete&&e.delete(o),s.push({key:o,...c})}return r.reverse?s.reverse():s},update:async(t,r,s)=>{a.update&&await a.update(t,r,s??{});let o=e.get(t);if(!o)return;let c={value:r,age:s&&s.updateAge?Date.now():o.age,...o.maxAge&&{maxAge:o.maxAge}};e.set(t,c),i={key:t,...c}},updateMany:async(t,r)=>{a.updateMany&&await a.updateMany(t,r??{});for(let s of t){let o=e.get(s[0]);if(!o)return;let c={value:s[1],age:r&&r.updateAge?Date.now():o.age,...o.maxAge&&{maxAge:o.maxAge}};e.set(s[0],c),i={key:s[0],...c}}},delete:async t=>{a.delete&&await a.delete(t),e.delete(t)},deleteMany:async t=>{a.deleteMany&&await a.deleteMany(t),t.length===0&&e.clear();for(let r of t)e.delete(r)},has:async t=>(a.has&&await a.has(t),e.has(t)),size:async()=>(a.size&&await a.size(),e.size),keys:async()=>(a.keys&&await a.keys(),[...e.keys()]),values:async()=>{a.values&&await a.values();let t=[];for(let r of[...e.values()])t.push(r.value);return t},clear:async()=>(a.clear&&await a.clear(),await h()),memory:async()=>{a.memory&&await a.memory();let t=[...e.keys()].toString()+[...e.values()].toString(),r=Buffer.from(t);return Buffer.byteLength(r)},recent:async()=>(a.recent&&await a.recent(),i),maxAge:async t=>(a.maxAge&&await a.maxAge(t),t&&(d=typeof t=="number"?t*1e3:typeof t=="string"?(0,M.default)(t):6e5,await h()),d),maxAmount:async t=>(a.maxAmount&&await a.maxAmount(t),t&&(l=t??1e4,await h()),l),newest:async()=>{if(e.size===0)return;let t=0,r;return e.forEach(async(s,o)=>{s.age>t&&(t=s.age,r={key:o,value:s.value,age:s.age,...s.maxAge&&{maxAge:s.maxAge}})}),r},oldest:async()=>{if(e.size===0)return;let t=0,r;return e.forEach(async(s,o)=>{(t===0||s.age<t)&&(t=s.age,r={key:o,value:s.value,age:s.age,...s.maxAge&&{maxAge:s.maxAge}})}),r},on:async(t,r)=>{a[t]=r},dump:async()=>{if(e.size===0)return[];let t=[],r=[...e.keys()];for(let s of r){let o=e.get(s);!o||t.push({key:s,...o})}return t}}},z=K;
{
"name": "cachu",
"version": "5.2.0-canary.1",
"version": "5.2.0-canary.2",
"description": "🦝 Simple, Minimalistic KV Cache",

@@ -9,2 +9,3 @@ "types": "./types/index.d.ts",

"build": "esbuild src/index.ts --bundle --minify --format=cjs --outfile=dist/index.js",
"publish:canary": "npm run build && npm publish --tag canary",
"publish:patch": "npm run build && npm version patch && npm publish",

@@ -11,0 +12,0 @@ "publish:minor": "npm run build && npm version minor && npm publish",

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