simple-ratelimit
v1.0.0
Published
A simple library for exponential rate-limiting
Downloads
2
Readme
#Simple-ratelimit Intended for login systems
###Usage:
var limit = require('simple-ratelimit');
//Get your last attempt time and number of attempts from your database
var lastAttempt = new Date('2015-2-2');
var attempts = 4;
//Two ways:
if(limit(lastAttempt, attempts)){ ///returns boolean if is rate limit
//We're being limited
//You can also add your own logic to add a maximum amount of attempts here.
}
//Or with a callback, containing more info
limit(lastAttempt, attempts, function(limited, requiredWait, elapsed) {
//limited is a boolean of wether or not we're rate limited
//requiredWait is the total wait in minutes required since lastAttempt
//elapsed is the amount of minutes since lastAttempt
//You can also add your own logic to add a maximum amount of attempts here.
});