Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

hash-o-matic

Package Overview
Dependencies
Maintainers
1
Versions
4
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

hash-o-matic

Pass objects or variables and the generated hash will be the same regardless of the order the parameters were passed.

  • 0.1.3
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
1
Created
Source

hash-o-matic

Hash up an unlimited number of values, but the problem is that the final hashed value is dependent on the order in which these values are added. What hash-o-matic does is it will order the object's properties by the property name before hashing. This is useful if you frequently hash the same variables through-out your app(s) but can't recall the order in which the values were added. The only real catch is the variables must have the same naming throughout your code.

Installation

npm install hash-o-matic

Usage

/* look at the unit tests for more examples */

var hashomatic = require('hash-o-matic');	
var caseinsensitive = true;
var normalizestrings = true;

var hash, hash2;

// Simple string hashing
hash = hashomatic.hash('the quick brown fox jumps over the lazy dog');
console.log(hash);

// 'case insensitive(by lower casing all)' string hashing
hash = hashomatic.hash('ThE Quick Brown fOx jUmps oveR the laZy dog', caseinsensitive, normalizestrings);
hash2 = hashomatic.hash('tHe qUICK bROWN FoX JuMPS OVEr THE LAzY DOG', caseinsensitive, normalizestrings);
console.log(hash === hash2); // true

// Object hashing; ordering, case, and normalized strings
var object = {'a': "", "b": "not empty", 'c': "", d: null},
    object2 = {"a": '', 'b': 'not empty', "c": '', d: ""};

hash = hashomatic.hash(object, caseinsensitive, normalizestrings);
hash2 = hashomatic.hash(object2, caseinsensitive, normalizestrings);
console.log(hash === hash2); // true

Tests

mocha test/*.js

Contributing

In lieu of a formal styleguide, take care to maintain the existing coding style. Add unit tests for any new or changed functionality. Lint and test your code.

Release History

  • 0.1.0 Initial release

Keywords

FAQs

Package last updated on 26 Jun 2014

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc