Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

rolling-rate-limiter

Package Overview
Dependencies
Maintainers
1
Versions
32
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

rolling-rate-limiter - npm Package Compare versions

Comparing version 0.1.5 to 0.1.6

17

index.js

@@ -35,3 +35,3 @@ var assert = require("assert");

}
return function (id, cb) {

@@ -42,6 +42,6 @@ if (!cb) {

}
assert.equal(typeof cb, "function", "Callback must be a function.");
var now = microtime.now();

@@ -58,3 +58,3 @@ var key = namespace + id;

if (err) return cb(err);
var userSet = zrangeToUserSet(resultArr[1]);

@@ -67,3 +67,3 @@

var remaining = maxInInterval - userSet.length - 1;
if (tooManyInInterval || timeSinceLastRequest < minDifference) {

@@ -90,3 +90,3 @@ result = Math.min(userSet[0] - now + interval, minDifference ? minDifference - timeSinceLastRequest : Infinity);

}
var now = microtime.now();

@@ -96,2 +96,4 @@ var clearBefore = now - interval;

clearTimeout(timeouts[id]);
delete timeouts[id];
var userSet = storage[id] = (storage[id] || []).filter(function(timestamp) {

@@ -106,3 +108,3 @@ return timestamp > clearBefore;

var remaining = maxInInterval - userSet.length - 1;
if (tooManyInInterval || timeSinceLastRequest < minDifference) {

@@ -117,2 +119,3 @@ result = Math.min(userSet[0] - now + interval, minDifference ? minDifference - timeSinceLastRequest : Infinity);

delete storage[id];
delete timeouts[id];
}, interval / 1000); // convert to miliseconds for javascript timeout

@@ -119,0 +122,0 @@

{
"name": "rolling-rate-limiter",
"version": "0.1.5",
"version": "0.1.6",
"description": "Rate limiter that supports a rolling window, either in-memory or backed by redis",

@@ -5,0 +5,0 @@ "main": "index.js",

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc