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 🙏

© 2025 – Pkg Stats / Ryan Hefner

node-hashit

v0.4.0

Published

Node.js object hash library

Readme

node-hashit

Fast node.js hash library with sorting and typing. Provides Hasher class. stringifyit provides stringify Symbol to allow you customize stringifying your own classes.

Using node.js crypto module and stringifyit library. For browsers you can use crypto-browserify or only stringifyit library.

See benchmarks for compare to other libs.

Install

npm i node-hashit --save

Features

  • Supports node.js >= 4.0.0
  • Supports Map/WeakMap, Set/WeakSet and typed arrays
  • Supports algorithms and encodings from node.js crypto module
  • Supports sort Set, Map, object keys and optional sort arrays
  • Supports custom stringify rules for user-defined classes (provided by stringifyit library)
  • One of the fastest hash libraries

API

Classes

Functions

Hasher

Provides interface to hash any value

Kind: global class

new Hasher([options])

| Param | Type | | --- | --- | | [options] | options |

hasher.update(value, [inputEncoding])

Updates hash with stringified value

Kind: instance method of Hasher
Throws:

  • HashitRangeError

| Param | Type | Description | | --- | --- | --- | | value | * | | | [inputEncoding] | string | Input encoding |

hasher.digest([outputEncoding]) ⇒ string | Buffer

Kind: instance method of Hasher
See: https://nodejs.org/api/crypto.html#crypto_hash_digest_encoding

| Param | Type | Description | | --- | --- | --- | | [outputEncoding] | string | Output encoding (if null Buffer will be returned) |

Hasher~options : Stringifier~options

Kind: inner typedef of Hasher
See

Properties

| Name | Type | Default | Description | | --- | --- | --- | --- | | algorithm | string | "md5" | Hash algorithm | | inputEncoding | string | "utf8" | Input encoding | | outputEncoding | string | "hex" | Output encoding (if null Buffer will be returned) |

hashit(value, [options]) ⇒ string

Helper for simple hash single value

Kind: global function

| Param | Type | | --- | --- | | value | * | | [options] | options |

Example

const {hashit} = require('node-hashit');

hashit({key: 'value', value: 'key'}) === hashit({value: 'key', key: 'value'}); // true
hashit(new Set(['value1', 'value2'])) === hashit(new Set(['value2', 'value1'])); // true
hashit(new Map([['key', 'value'], ['value', 'key']])) === hashit(new Map([['value', 'key'], ['key', 'value']])); // true
hashit([1, 2, 3]) === hashit([1, 2, 3]); // true
hashit([1, 2, 3], {sortArrays: true}) === hashit([1, 3, 2], {sortArrays: true}); // true

hashit([1, 2, 3]) === hashit([1, 3, 2]); // false
hashit(5) === hashit('5'); // false

Benchmarks

Benchmarked with Node.js v6.9.5

Usage

  • npm run benchOps to run comparison operations/second with other libs for different cases
  • npm run benchHeap to run comparison heap using with other libs for complex cases
  • npm run benchSpeed to run benchmarking hashit operations/second for different cases

Results

Operations/second comparison (+includePrimitiveTypes +sortArrays) source

hashit/array x 255,710 ops/sec ±1.54% (86 runs sampled)
nodeObjectHash/array x 174,084 ops/sec ±2.11% (84 runs sampled)
hashObject/array x 140,706 ops/sec ±1.56% (82 runs sampled)
objectHash/array x 48,767 ops/sec ±1.55% (88 runs sampled)

hashit/object x 426,051 ops/sec ±1.18% (82 runs sampled)
nodeObjectHash/object x 354,923 ops/sec ±1.59% (83 runs sampled)
hashObject/object x 350,324 ops/sec ±1.40% (84 runs sampled)
objectHash/object x 27,030 ops/sec ±1.39% (83 runs sampled)

hashit/nestedObject x 23,762 ops/sec ±1.33% (87 runs sampled)
nodeObjectHash/nestedObject x 16,252 ops/sec ±4.74% (81 runs sampled)
hashObject/nestedObject x 17,689 ops/sec ±1.92% (85 runs sampled)
objectHash/nestedObject x 657 ops/sec ±1.27% (84 runs sampled)

hashit/complexObject_5items x 19,677 ops/sec ±1.54% (86 runs sampled)
nodeObjectHash/complexObject_5items x 9,922 ops/sec ±1.58% (87 runs sampled)
hashObject/complexObject_5items x 2,561 ops/sec ±1.65% (84 runs sampled)
objectHash/complexObject_5items x 1,433 ops/sec ±1.37% (85 runs sampled)

hashit/complexObject_10items x 10,385 ops/sec ±1.58% (86 runs sampled)
nodeObjectHash/complexObject_10items x 4,906 ops/sec ±2.10% (86 runs sampled)
hashObject/complexObject_10items x 1,331 ops/sec ±1.21% (85 runs sampled)
objectHash/complexObject_10items x 722 ops/sec ±1.65% (82 runs sampled)

hashit/complexObject_100items x 944 ops/sec ±1.55% (84 runs sampled)
nodeObjectHash/complexObject_100items x 483 ops/sec ±1.72% (84 runs sampled)
hashObject/complexObject_100items x 129 ops/sec ±1.35% (70 runs sampled)
objectHash/complexObject_100items x 66.61 ops/sec ±1.44% (65 runs sampled)

hashit faster in cases: array, object, nestedObject, complexObject_5items, complexObject_10items, complexObject_100items (6)

Heap using comparison (+includePrimitiveTypes +sortArrays) source

| Library | Time (ms) | Memory (Mb) | |---------------------------------------|------------|--------------------| | hashit-0.3.2 | 2120.435 | 42 | | node-object-hash-1.2.0 | 2635.670 | 39 | | object-hash-1.1.5 | 17325.391 | 62 | | hash-object-0.1.7 | 9762.324 | 51 |

Operations/second hashit benchmarking (+includePrimitiveTypes -sortArrays) source

array x 362,314 ops/sec ±0.97% (84 runs sampled)
object x 434,386 ops/sec ±1.78% (85 runs sampled)
nestedObject x 23,896 ops/sec ±1.35% (85 runs sampled)
complexObject_5items x 20,820 ops/sec ±1.56% (86 runs sampled)
complexObject_10items x 10,930 ops/sec ±1.55% (84 runs sampled)
complexObject_100items x 981 ops/sec ±1.68% (83 runs sampled)
set x 119,927 ops/sec ±2.33% (83 runs sampled)
map x 111,666 ops/sec ±2.27% (83 runs sampled)

Links

License

MIT