UNPKG

tiny-essentials

Version:

Collection of small, essential scripts designed to be used across various projects. These simple utilities are crafted for speed, ease of use, and versatility.

19 lines (14 loc) β€’ 1.59 kB
### πŸ†• `TinyRateLimiter` Updates in v1.10.0 🎯 This version brings a bunch of internal improvements and cleanup to `TinyRateLimiter`, making it faster, cleaner, and more memory-friendly. Here’s what’s new: * πŸ“¦ **New memory optimization logic**: The limiter can now keep only the latest N entries per group (`#maxMemory`) to reduce memory usage. Automatically calls `onMemoryExceeded(groupId)` if defined. * πŸ§ͺ **Improved rate limit check**: The `isRateLimited()` method is now faster and more consistent, even when `interval` is disabled. * 🧼 **Better cleanup system**: Groups now use either their own TTL or fallback to `maxIdle`, and the internal `_cleanup()` handles expiration gracefully. * πŸ“Š **New metrics method**: `getMetrics(groupId)` now returns hit count, last hit, spacing average, and time since last hit in one call! * πŸ” **New helpers**: * `getAllUserMappings()` – returns user β†’ group map as plain object πŸ“„ * `getAverageHitSpacing()` – computes average time between hits * `getTimeSinceLastHit()` – useful for time-based triggers * ⚠️ **Deprecated**: `reset(userId)` is now deprecated β€” use `resetUserGroup(userId)` instead. * πŸš€ **Fully isolated internals**: All core options (`interval`, `maxHits`, `maxIdle`) now throw if misconfigured. Stronger encapsulation and clearer API. This release keeps the class drop-in compatible with previous versions but brings real performance and control benefits under scale. Enjoy! πŸ§©πŸ’‘ **Full Changelog**: https://github.com/JasminDreasond/Tiny-Essentials/compare/1.9.2...1.10.0