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

hashdata

v0.0.3

Published

Hash data within arrays. For when you need to hash your data and maintain numeric precision!

Downloads

15

Readme

Hash that Data!

When you need to hash your data and maintain numeric precision!

Before proceeding, it is important you check out HashIds. No, Really!

Ok. So let us proceed...

Why Hash Arrays of Data?

So, often you find yourself needing to generate hashes that can be used (especially within URL's) that encode certain data. Often, these hashes are limited and no sooner do you start working on a complex system do you realize you need to pass around more data.

Arrays are the simplest objects and perfect for passing around such data. It is for this reason that HashIds and this module exist.

Practicals

So let us take this practical scenario:

  • Your company sells products via an e-commerce site and through numerous merchants in different countries.
  • Every merchant has a unique (numeric) ID
  • Every product has a (numeric) product code
  • You want an easy way to monitor who sells what.

An easy solution is to generate a hash from that data:

Say, the array [254, 463, 8097] represents the data as follows : ['country-code', 'merchant-id', 'product-code']. You can then generate a hash(code) that packages all this data and can be used within your URL's.

Using this module that hash would be Z-HQb2QKYJ4. Sweet!

And so...

At this point, you would be justified to ask why then shouldn't you just use HashIds?

Well, you should. Really! Having run about 100,000 tests, this library is still in its infancy. But here is why it was born...

Back to the scenario above. Suppose then that you wanted to capture the following data also;

  • Price of the product
  • Percent discount allowed for respective merchant (normally, merchants who sell more are allowed bigger discounts, No?)

This then becomes our array: [ 254, 463, 8097, 99.99, 10.5 ] where ['country-code', 'merchant-id', 'product-code', 'product-price', 'percentage-discount']

With HashData that generates the following Hash: JW-Gb3a2t4JLJ9PhtVYMB5D-BE. Nice!

And that is the greatest motivation for writing this module. Because almost every other module works with integers only!

So in short, I wrote this coz I needed a module that will:

  1. Hash both integers & floats.

  2. Work with incredibly big integers! This module has been tested with numbers upto 10e15;

  3. As much as possible, generate human-friendly hashes (like CF4EG3JAK7B). This module does not use the letters 'I|i, L|l, O|o, S|s' because they resemble the numerals '1, 0 & 5' and thus would result in confusing hashes.

Time to code!

First install using npm install -s hashdata


const hashdata = require('../');


let array = [ 254, 463, 8097, 99.99, 10.5 ];

//Encode
let encoded = hashdata.encode(array);
//Decode
let decoded = hashdata.decode(encoded);

console.log('Hash:' + encoded);
console.log('IN' , array);
console.log('OUT', decoded);

This should output:

Hash: JW-Gb3a2t4JLJ9PhtVYMB5D-BE
IN [ 254, 463, 8097, 99.99, 10.5 ]
OUT [ 254, 463, 8097, 99.99, 10.5 ]

Simple!

API

This module exposes only two methods...

.encode( arr [,random] )

  • arr : Array to encode/hash

  • random : If set to true, hashes generated are much more random.

.decode( hash )

  • hash : The encoded hash to decode.

Generating your own Hash-Map

This Module works by using a hash-map that is stored at ./data/letter_map.json.

You can create your own map by running the make.js file node ./node_modules/hashdata/make.js ie. within the module folder.

This creates a new hash-map file that will then be used to generate your hashes.

Normally, a new hash-map file will not improve compression or any other features but only generate hashed that are unique/different.

Be wise Now, will you?

This module is not written with any notion of security whatsoever in mind! So never use it to hash sensitive data!

Also, this module does not seek or attempt to compress data! Actually, it is impossible to keep hashes neat and pretty while still achieving any reasonable form of compression. So if you seek shorter hashes, then this is not for you! From tests run, the average compression is a paltry 12-15%.

Wait, so you need to hash Objects too?

OK, Check out my other module Object-Encode. That one does a little more to obscure your data but don't be fooled. Public Hashes are never to be used with sensitive information! Period!

Tests

First install dev dependencies then run npm run test. Head to the ./tests folder to view test files for more.

This Module comfortably encodes/decodes arrays where:

  • Array size does not exceed 100 values &
  • The largest value does not exceed 10^15

TODO

  • Tell me what you think we should add.
  • Find even better ways to make hashes more human friendly.
  • Increase accuracy for arrays bigger than 100 values. Doubt anyone will ever need this. But...