New Case Study:See how Anthropic automated 95% of dependency reviews with Socket.Learn More
Socket
Sign inDemoInstall
Socket

just-throttle

Package Overview
Dependencies
Maintainers
1
Versions
18
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

just-throttle - npm Package Compare versions

Comparing version 1.1.0 to 2.0.0

19

index.js
module.exports = throttle;
function throttle(fn, interval, callFirst) {
function throttle(fn, interval, options) {
var wait = false;
var callNow = false;
var leading = (options && options.leading);
var trailing = (options && options.trailing);
if (leading == null) {
leading = true; // default
}
if (trailing == null) {
trailing = !leading; //default
}
if (leading == true) {
trailing = false; // forced because there should be invocation per call
}
return function() {
callNow = callFirst && !wait;
var callNow = leading && !wait;
var context = this;

@@ -14,3 +25,3 @@ var args = arguments;

wait = false;
if (!callFirst) {
if (trailing) {
return fn.apply(context, args);

@@ -17,0 +28,0 @@ }

{
"name": "just-throttle",
"version": "1.1.0",
"version": "2.0.0",
"description": "return a throttled function",

@@ -21,2 +21,2 @@ "main": "index.js",

}
}
}

@@ -11,9 +11,12 @@ ## just-throttle

const fn1 = throttle(() => console.log('hello'), 500, true);
const fn1 = throttle(() => console.log('hello'), 500, {leading: true});
setInterval(fn1, 400);
// logs 'hello' immediately and then every 500ms
const fn2 = throttle(() => console.log('hello'), 500);
const fn2 = throttle(() => console.log('hello'), 500, {trailing: true});
setInterval(fn2, 400);
// logs 'hello' after 500ms and then every 500ms
const fn2 = throttle(() => console.log('hello'), 500, {leading: true, trailing: true});
// forces trailing to false
```
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