1.0.4 • Published 3 years ago

simplejs-rate-limiter v1.0.4

Weekly downloads
11
License
ISC
Repository
github
Last release
3 years ago

SimpleRateLimiter

SimpleJSRateLimitersuper is a simple RateLimiter integrated with lru cache package.

const { RateLimiterSingleton } = require("simplejs-rate-limiter");

//SetRateLimitOptions(timelimit in milliseconds, maximumRequestInTimeLimit);
RateLimiterSingleton.SetRateLimitOptions(4000, 2);

//ThrowLimitExceptionIfNecessary('unique identifier for a specific user')
RateLimiterSingleton.GetInstance().ThrowLimitExceptionIfNecessary("2");
RateLimiterSingleton.GetInstance().ThrowLimitExceptionIfNecessary("3");

//should do nothing

////////////////////////////////////////////////////////////////////////////
RateLimiterSingleton.SetRateLimitOptions(4000, 2);
RateLimiterSingleton.GetInstance().ThrowLimitExceptionIfNecessary("2");
RateLimiterSingleton.GetInstance().ThrowLimitExceptionIfNecessary("2");
RateLimiterSingleton.GetInstance().ThrowLimitExceptionIfNecessary("2");

//should throw rate limit exception
1.0.4

3 years ago

1.0.2

3 years ago

1.0.3

3 years ago

1.0.1

3 years ago