Socket
Book a DemoInstallSign in
Socket

frequency-counter

Package Overview
Dependencies
Maintainers
1
Versions
2
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

frequency-counter

Count the number of occurrences of a repeating event per unit of time

latest
Source
npmnpm
Version
1.0.1
Version published
Weekly downloads
146
17.74%
Maintainers
1
Weekly downloads
 
Created
Source

frequency-counter

Count the number of occurrences of a repeating event per unit of time.

Build status js-standard-style

Installation

npm install frequency-counter --save

Usage example

Example HTTP server responding with the number of requests per minute (rpm):

const http = require('http')
const Freq = require('frequency-counter')

// if no arguments are given a window of one minute is used
const counter = new Freq()

const server = http.createServer(function (req, res) {
  // increment the count
  counter.inc()
 
  // return current frequency to client
  res.end('rpm: ' + counter.freq() + '\n')
})

server.listen(3000)

API

counter = new Freq([windowSize])

Initialize the frequency counter. Optionally set a custom window size in seconds over which the frequency should be calcuated (default: 60).

counter.inc([amount])

Track an occurrence by incrementing a counter. Optionally provide the amount to increment by (default: 1).

number = counter.freq()

Calculate and return the current frequency.

License

MIT

Keywords

freq

FAQs

Package last updated on 16 Apr 2018

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