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

counter-hash-js

v0.2.0

Published

A Node.js library implementing a simple CounterHash class, for incrementing and decrementing keys.

Downloads

9

Readme

counter-hash-js

Purpose

A Node.js library implementing a simple CounterHash class, for incrementing and decrementing keys.

Often it is useful to traverse some data structure, accumulating conters in the process. Class CounterHash provides functions to increment, decrement, add, subtract, and obtain the sum, values, and sorted-keys of the hash.

Examples

Setup

Add counter-hash-js to your project or package.json file:

npm install counter-hash-js

Require counter-hash-js in your code:

CounterHash  = require("counter-hash-js").CounterHash

Note: this library is now implemented in TypeScript, but these examples are in CoffeeScript. For users of TypeScript, see the declaration file for this library at:

https://github.com/cjoakim/counter-hash-js/blob/master/lib/counter-hash-js.d.ts

CounterHash

Methods value(key), increment(key), decrement(key), add(key, n), subtract(key, n), value(key), sum(), sorted_keys(), and sorted_tuples() are available.

h = new CounterHash()
h.increment('a')
h.increment('a')
h.increment('b')
h.decrement('q')
h.increment('z')

h.sum()       -> 3

h.value('a')  -> 2
h.value('x')  -> undefined

h.add('x', 100)
h.subtract('x', 7)

h.value('x')  -> 93

h.sorted_keys() -> [ 'a', 'b', 'q', 'x', 'z' ]

h.sorted_tuples() -> [ ['a', 2], ['b', 1],['q', -1], ['z', 1] ]

CounterHash.VERSION  -> '0.2.0'

Test Results

Running "mocha_istanbul:coverage" (mocha_istanbul) task

  CounterHash
    read_file_sync
      ✓ should have a constructor
      ✓ should have a VERSION
      ✓ should implement methods: increment, decrement, and sum
      ✓ should implement methods: add and subtract
      ✓ should implement method: values
      ✓ should implement method: sorted_keys
      ✓ should implement method: sorted_tuples


  7 passing (10ms)

=============================================================================
Writing coverage object [/Users/cjoakim/github/counter-hash-js/coverage/coverage.json]
Writing coverage reports at [/Users/cjoakim/github/counter-hash-js/coverage]
=============================================================================

=============================== Coverage summary ===============================
Statements   : 100% ( 54/54 )
Branches     : 88.89% ( 16/18 )
Functions    : 100% ( 11/11 )
Lines        : 100% ( 54/54 )
================================================================================

Release History

  • 2015-05-02   v0.2.0  Implemented in TypeScript; added file 'counter-hash-js.d.ts'.
  • 2015-02-20   v0.1.2  Added method 'sorted_tuples()'.
  • 2015-01-13   v0.1.1  Docs updated.
  • 2015-01-13   v0.1.0  Initial working version.
  • 2015-01-13   v0.0.2  alpha 2
  • 2015-01-13   v0.0.1  alpha 1