Socket
Socket
Sign inDemoInstall

throttleit

Package Overview
Dependencies
0
Maintainers
24
Versions
5
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    throttleit

Throttle a function


Version published
Weekly downloads
5.4M
increased by0.68%
Maintainers
24
Install size
5.21 kB
Created
Weekly downloads
 

Package description

What is throttleit?

The throttleit package is a utility that allows you to throttle a function, meaning it limits the rate at which a function can fire. This is particularly useful for handling repetitive events that you want to control, such as window resizing, scrolling, or keypresses in a performant way.

What are throttleit's main functionalities?

Throttling function calls

This code sample demonstrates how to use throttleit to throttle a window resize event handler. The onResize function will not be called more than once every 200 milliseconds, no matter how often the resize event fires.

const throttle = require('throttleit');

function onResize(event) {
  console.log('Window resized.');
}

window.addEventListener('resize', throttle(onResize, 200));

Other packages similar to throttleit

Readme

Source

throttle

Throttle a function

Installation

$ component install component/throttle

Example

var throttle = require('throttle');
window.onresize = throttle(resize, 200);

function resize(e) {
  console.log('height', window.innerHeight);
  console.log('width', window.innerWidth);
}

API

throttle(fn, wait)

Creates a function that will call fn at most once every wait milliseconds.

Supports leading and trailing invocation.

fn will receive last context (this) and last arguments passed to a throttled wrapper before fn was invoked.

License

MIT

FAQs

Last updated on 27 Feb 2015

Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

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

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc