simplejs-rate-limiter

1.0.4 • Public • Published

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

Readme

Keywords

none

Package Sidebar

Install

npm i simplejs-rate-limiter

Weekly Downloads

0

Version

1.0.4

License

ISC

Unpacked Size

2.96 kB

Total Files

8

Last publish

Collaborators

  • carmigalc