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 🙏

© 2024 – Pkg Stats / Ryan Hefner

@buzuli/meter

v1.4.0

Published

Metrics collection utility with support for (de)serialization.

Downloads

337

Readme

@buzuli/meter

Simple metrics collection utility with support for serialization and deserialization.

Usage

The package exports a function which creates a new Meter. It can also be used to collect results from multiple meters or other objects.

meter(src)

  • src: string | Meter | object | Array | The source from which the new Meter should attempt to initialize.

Meter properties:

  • isMeter: true
  • add: (metric: string, value: number = 1) -> number | Increments a metric, initializing it if absent. Returns the updated metric's value.
  • min: (metric: string, value: number) -> number | Update a metric of the supplied value is smaller or the metric is not set. Returns the updated metric's value.
  • max: (metric: string, value: number) -> number | Update a metric of the supplied value is larger or the metric is not set. Returns the updated metric's value.
  • set: (metric: string, value: number = 0) -> number | Set the value of a metric. Returns the new value.
  • get: (metric: string) -> number | Get the value associated with a metric. Will be 0 if the metric was missing.
  • clear: () -> nil | Removes all metrics from the Meter.
  • forEach: ({ metric, count }) -> nil -> nil | Applies the supplied function to every metric in the Meter.
  • entries: Iterator[[string, number]] | Supplies an iterator supplying each metric/count pair as an array of the form [metric, count].
  • metrics: Iterator[string] | Supplies an iterator supplying all of the metric names.
  • map: `({ metric, count }) -> T -> Array[T] | Maps all entries into a new array via the supplied mapper function
  • asObject: ({ sort = false, desc = false }) -> object | Converts this meter into a simple object. With each metric key as a field name mapping to its count.
    • Unsorted by default, but may be sorted by keys (sort is true, keys, or metics), or sorted by values (sort is values or counts).
    • Defaults to ascending order, but order may be switched by setting desc to true.
  • merge: (Meter) -> nil | Merges all of the metrics from another Meter into this Meter.
  • mergeMap: (Map) -> nil | Merges all of a Map's valid fields (strings mapping to numbers) into this Meter.
  • mergeObject: (object) -> nil | Merges all of an object's valid fields (strings mapping to numbers) into this Meter.
  • serialize: () -> string | Returns a JSON structure which can be imported directly into a new Meter.
  • size: () -> number | Returns the size of the meter (the number of distinct metric keys with associated counts).

Example

const meter = require('@buzuli/meter')
const metrics = meter()
metrics.add('calls')
metrics.set('age', 275)
metrics.add('calls')
metrics.add('age', 25)
metrics.forEach(({ metric, count }) => console.info(`${metric} => ${count}`))
// Outputs:
//calls => 2
//age => 300