UNPKG

limiter.js

Version:

limiter.js is a Node.js/TypeScript library that provides simple Rate limiter protection for Express applications. It tracks requests per IP address and enforces rate limits within a sliding time window. If an IP exceeds the allowed requests, limiter.js ca

34 lines (33 loc) 1.1 kB
export declare class IPTracker { private ipAddress; private hits; bannedUntil: number | null; private banCount; private permanentBan; constructor(ipAddress: string); recordHit(timestamp: number): void; /** * Get the number of hits in the last `windowMs` milliseconds. * @param windowMs The time window in milliseconds to check for hits. * @returns The count of hits in the specified time window. */ getHitCountInWindow(windowMs: number): number; /** * Check if the IP is currently banned. * @param currentTime The current time in milliseconds since epoch. * @returns True if the IP is banned, false otherwise. */ isBanned(currentTime: number): boolean; getIsPermanentlyBanned(): boolean; getBanCount(): number; /** * Ban the IP for a specified duration in milliseconds. * @param durationMs The duration in milliseconds for which to ban the IP. */ ban(durationMs: number): void; /** * Permanently ban the IP. */ banPermanently(): void; getIpAddress(): string; }