npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

caring-band

v1.4.3

Published

Realtime Streaming Statistics

Readme

Statistical Object

Allows to easily store: count, min, max, last, sum, sum-of-squares. This is inspired by CouchDB's _stats built-in reduce function. Results are stored as big-rational numbers.

bigRat = require 'big-rational'

Each statistical object stored offers the following fields:

  • count, the number of items submitted
  • min, the numerically smallest item submitted
  • max, the numerically largest item submitted
  • last, the most recent item submitted
  • sum, the numerical sum of all items submitted
  • sumsqr, the sum of squares of each item submitted

A new item is submitted either:

  • by using add(number);

  • by using add(), in which case the number is assumed to be 0 (and only count is meaningful).

    class CaringBandData constructor: -> @count = new bigRat 0 @min = null @max = null @last = null @sum = new bigRat 0 @sumsqr = new bigRat 0

    add: (number) ->
      number ?= 0
      number = new bigRat number
      @last = number
      @count = @count.add 1
      if not @min? or @min.greater number
        @min = number
      if not @max? or number.greater @max
        @max = number
    
      @sum = @sum.add number
      @sumsqr = @sumsqr.add number.times number
      this
    
    toJSON: (decimals) ->
      text = []
      for own k,v of this when v?
        text.push """
          "#{k}": #{v.toDecimal decimals}
        """
      "{#{text.join ', '}}"

Storage Object

The module exports a storage object which allows you to:

  • add(key,item): add a new numerical item to a key's statistical object; returns the new statistical object;
  • add(key): count a new entry; the value is assumed to be zero; returns the new statistical object;
  • get(key): retrieve the statistical object defined above;
  • delete(key): delete the statisitcal object for the key.

Keys might be any JSON-compatible types. Non-string keys are converted to strings using JSON.stringify.

The storage object is also an EventEmitter.

{EventEmitter} = require 'events'

class CaringBand extends EventEmitter

  constructor: ->
    @data = {}

  add: (key,number) ->
    if typeof key isnt 'string'
      key = JSON.stringify key

    @data[key] ?= new CaringBandData()
    value = @data[key].add number

It will emit add when a value is updated.

    @emit 'add', {key,number:value.last,value}

  get: (key) ->
    if typeof key isnt 'string'
      key = JSON.stringify key
    @data[key]

  delete: (key) ->
    if typeof key isnt 'string'
      key = JSON.stringify key
    delete @data[key]

It will emit delete when a value is deleted.

    @emit 'delete', {key}

  toJSON: (precision) ->
    hash = []
    for own key,value of @data
      do (key,value) ->
        hash.push (JSON.stringify key) + ':' + value.toJSON precision
    '{' + (hash.join ',') + '}'

module.exports = CaringBand
module.exports.data = CaringBandData