
Research
Security News
The Growing Risk of Malicious Browser Extensions
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
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
v0.2.0
FAQs
Cooldown timer for rate-limiting events
The npm package cooldown receives a total of 17 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.
Research
Security News
Socket researchers uncover how browser extensions in trusted stores are used to hijack sessions, redirect traffic, and manipulate user behavior.
Research
Security News
An in-depth analysis of credential stealers, crypto drainers, cryptojackers, and clipboard hijackers abusing open source package registries to compromise Web3 development environments.
Security News
pnpm 10.12.1 introduces a global virtual store for faster installs and new options for managing dependencies with version catalogs.