Security News
Fluent Assertions Faces Backlash After Abandoning Open Source Licensing
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
timers-ext
Advanced tools
The timers-ext npm package provides extended timer functionalities for JavaScript, including delay, debounce, throttle, and more. It is useful for managing and controlling the execution of functions over time.
delay
The delay function pauses the execution of the code for a specified amount of time. In this example, the code waits for 2 seconds before logging 'End'.
const delay = require('timers-ext/delay');
async function example() {
console.log('Start');
await delay(2000); // Delay for 2 seconds
console.log('End');
}
example();
debounce
The debounce function ensures that a function is only called once after a specified delay period has passed since the last time it was invoked. This is useful for events like window resizing.
const debounce = require('timers-ext/debounce');
function onResize() {
console.log('Resized');
}
const debouncedResize = debounce(onResize, 300);
window.addEventListener('resize', debouncedResize);
throttle
The throttle function ensures that a function is called at most once in a specified time period. This is useful for events like scrolling where you want to limit the number of times a function is called.
const throttle = require('timers-ext/throttle');
function onScroll() {
console.log('Scrolled');
}
const throttledScroll = throttle(onScroll, 1000);
window.addEventListener('scroll', throttledScroll);
Lodash is a popular utility library that provides a wide range of functions for common programming tasks, including debounce and throttle. It is more comprehensive than timers-ext and includes many other utilities for working with arrays, objects, and more.
Underscore is another utility library similar to Lodash that provides a variety of functional programming helpers, including debounce and throttle. It is less feature-rich than Lodash but still widely used for its simplicity and ease of use.
The async library provides powerful functions for working with asynchronous JavaScript, including control flow, collections, and more. While it does not focus specifically on timers, it offers various utilities for managing asynchronous operations.
$ npm install timers-ext
To port it to Browser or any other (non CJS) environment, use your favorite CJS bundler. No favorite yet? Try: Browserify, Webmake or Webpack
Maximum possible timeout value in milliseconds. It equals to maximum positive value for 32bit signed integer, so 2³¹ (2147483647), which makes it around 24.9 days
Returns function which when invoked will call fn function after specified timeout. If timeout is not provided nextTick propagation is used.
Makes sure to execute fn function only once after a defined interval of time (debounce). If timeout is not provided nextTick propagation is used.
var nextTick = require("next-tick");
var logFoo = function () { console.log("foo"); };
var logFooOnce = require("timers-ext/once")(logFoo);
logFooOnce();
logFooOnce(); // ignored, logFoo will be logged only once
logFooOnce(); // ignored
nextTick(function () {
logFooOnce(); // Invokes another log (as tick passed)
logFooOnce(); // ignored
logFooOnce(); // ignored
});
Validates timeout value.
For NaN
resolved timeout 0
is returned.
If timeout resolves to a number:
0
is returnedtimeout
value is returned$ npm test
To report a security vulnerability, please use the Tidelift security contact. Tidelift will coordinate the fix and disclosure.
FAQs
Timers extensions
The npm package timers-ext receives a total of 3,128,398 weekly downloads. As such, timers-ext popularity was classified as popular.
We found that timers-ext demonstrated a healthy version release cadence and project activity because the last version was released less than a year ago. It has 1 open source maintainer collaborating on the project.
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.
Security News
Fluent Assertions is facing backlash after dropping the Apache license for a commercial model, leaving users blindsided and questioning contributor rights.
Research
Security News
Socket researchers uncover the risks of a malicious Python package targeting Discord developers.
Security News
The UK is proposing a bold ban on ransomware payments by public entities to disrupt cybercrime, protect critical services, and lead global cybersecurity efforts.