Socket
Book a DemoInstallSign in
Socket

sliding-window-counter

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

sliding-window-counter

Count stuff within a time interval e.g. how many users logged in the last hour?

latest
Source
npmnpm
Version
0.2.4
Version published
Maintainers
1
Created
Source

sliding-window-counter

Count stuff within a time interval e.g. how many users logged in the last hour?

npm install sliding-window-counter

Usage - standard

var counter = require('sliding-window-counter');
var cnt = counter(10000); // Track events the last 10s

cnt(5); // add 5 events

setInterval(function() {
	cnt(1); // add 1 event
}, 2000);

setInterval(function() {
	console.log(cnt(), 'events during the last 10s');
}, 1000);

Usage - serialization

It is possible to serialize a counter, and reload the data later on.

var counter = require('sliding-window-counter');
var cnt = counter(10000);

// ... have the counter run for a while

var oldData = cnt.toJSON();
var newCnt = counter(oldData);
// ...

License

MIT

FAQs

Package last updated on 04 Mar 2014

Did you know?

Socket

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