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

throttleit

Package Overview
Dependencies
Maintainers
25
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

throttleit - npm Package Compare versions

Comparing version 1.0.1 to 2.0.0

index.d.ts

48

index.js

@@ -1,32 +0,24 @@

module.exports = throttle;
function throttle(function_, wait) {
let timeoutId;
let lastCallTime = 0;
/**
* Returns a new function that, when invoked, invokes `func` at most once per `wait` milliseconds.
*
* @param {Function} func Function to wrap.
* @param {Number} wait Number of milliseconds that must elapse between `func` invocations.
* @return {Function} A new function that wraps the `func` function passed in.
*/
return function throttled(...arguments_) { // eslint-disable-line func-names
clearTimeout(timeoutId);
function throttle (func, wait) {
var ctx, args, rtn, timeoutID; // caching
var last = 0;
const now = Date.now();
const timeSinceLastCall = now - lastCallTime;
const delayForNextCall = wait - timeSinceLastCall;
return function throttled () {
ctx = this;
args = arguments;
var delta = new Date() - last;
if (!timeoutID)
if (delta >= wait) call();
else timeoutID = setTimeout(call, wait - delta);
return rtn;
};
if (delayForNextCall <= 0) {
lastCallTime = now;
function_.apply(this, arguments_);
} else {
timeoutId = setTimeout(() => {
lastCallTime = Date.now();
function_.apply(this, arguments_);
}, delayForNextCall);
}
};
}
function call () {
timeoutID = 0;
last = +new Date();
rtn = func.apply(ctx, args);
ctx = null;
args = null;
}
}
module.exports = throttle;
{
"name": "throttleit",
"description": "Throttle a function",
"version": "1.0.1",
"keywords": [],
"funding": "https://github.com/sponsors/sindresorhus",
"repository": {
"type": "git",
"url": "git://github.com/sindresorhus/throttleit.git"
},
"devDependencies": {
"mocha": "^1.18.0"
},
"license": "MIT",
"component": {
"scripts": {
"throttle/index.js": "index.js"
}
},
"scripts": {
"test": "mocha --reporter spec"
}
"name": "throttleit",
"version": "2.0.0",
"description": "Throttle a function to limit its execution rate",
"license": "MIT",
"repository": "sindresorhus/throttleit",
"funding": "https://github.com/sponsors/sindresorhus",
"exports": {
"types": "./index.d.ts",
"default": "./index.js"
},
"main": "./index.js",
"types": "./index.d.ts",
"sideEffects": false,
"engines": {
"node": ">=18"
},
"scripts": {
"test": "xo && ava"
},
"files": [
"index.js",
"index.d.ts"
],
"keywords": [
"throttle",
"rate",
"limit",
"limited",
"rate-limit",
"ratelimit",
"throttling",
"optimization",
"performance",
"function",
"execution",
"interval",
"batch"
],
"devDependencies": {
"ava": "^5.3.1",
"xo": "^0.56.0"
},
"xo": {
"rules": {
"unicorn/prefer-module": "off"
}
}
}
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