feat: slugify, rate limit ed env helper con test

This commit is contained in:
2026-07-02 00:31:18 +02:00
parent c9a9ff91fd
commit 42d603b55b
5 changed files with 73 additions and 0 deletions
+17
View File
@@ -0,0 +1,17 @@
const buckets = new Map<string, number[]>();
export function rateLimit(key: string, max: number, windowMs: number): boolean {
const now = Date.now();
const recent = (buckets.get(key) ?? []).filter((t) => now - t < windowMs);
if (recent.length >= max) {
buckets.set(key, recent);
return false;
}
recent.push(now);
buckets.set(key, recent);
return true;
}
export function _resetBuckets(): void {
buckets.clear();
}