![require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages](https://cdn.sanity.io/images/cgdhsj6q/production/be8ab80c8efa5907bc341c6fefe9aa20d239d890-1600x1097.png?w=400&fit=max&auto=format)
Security News
require(esm) Backported to Node.js 20, Paving the Way for ESM-Only Packages
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Timer mechanism to place upper bound on rate of events.
npm install cooldown
This example reads lines of text from stdin. When 'spam' is entered, it will output 'spam' but only at a rate of once per 5 seconds. Entering 'reset' can reset the cooldown and allow 'spam' to succeed immediately after. Entering 'ready?' will display the state of the cooldown timer. The 'ready' event listener will automatically print when the timer is off cooldown.
var Cooldown = require('cooldown');
var readline = require('readline');
var rl = readline.createInterface({
input: process.stdin,
output: process.stdout
});
// Set limit to 5s
var cd = new Cooldown(5000);
cd.on('ready', console.log.bind('console', 'off cooldown'));
rl.on('line', function (line) {
switch (line) {
case 'spam':
if (cd.fire()) {
console.log('have some spam');
} else {
console.log('not yet');
}
break;
case 'ready?':
console.log(cd.ready ? 'yep' : 'nope');
break;
case 'reset':
// reset the cooldown
cd.reset();
break;
case 'quit':
cd.destroy();
rl.close();
break;
}
});
A cooldown timer with two states:
Return true if the timer was ready (and puts it on-cooldown).
If timer is on-cooldown, reset it back to ready.
Clear any timeouts and set timer to on-cooldown. It will never enter the 'ready' state unless it is reset.
Contains true if the timer is off cooldown and available to fire, else false.
Emitted whenever the timer comes back off cooldown.
Emitted whenever the timer goes on cooldown.
MIT
FAQs
Cooldown timer for rate-limiting events
The npm package cooldown receives a total of 0 weekly downloads. As such, cooldown popularity was classified as not popular.
We found that cooldown demonstrated a not healthy version release cadence and project activity because the last version was released 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
require(esm) backported to Node.js 20, easing the transition to ESM-only packages and reducing complexity for developers as Node 18 nears end-of-life.
Security News
PyPI now supports iOS and Android wheels, making it easier for Python developers to distribute mobile packages.
Security News
Create React App is officially deprecated due to React 19 issues and lack of maintenance—developers should switch to Vite or other modern alternatives.