Object-Hash
Generate hashes from objects and values in node and the browser. Uses node.js crypo module for hashing. Supports sha1, md5 and many others (depending on the host os).
var objectHash = require('object-hash');
objectHash(value, options);
Generate a hash from any object or type. Defaults to sha1 with hex encoding.
Installation
node:
npm install object-hash
browser: (/dist/object_hash.min.js)
<script src="object_hash.min.js" type="text/javascript"></script>
Example usage
var objectHash = require('object-hash');
var peter = {name: 'Peter', stapler: false, friends: ['Joanna', 'Michael', 'Samir'] };
var michael = {name: 'Michael', stapler: false, friends: ['Peter', 'Samir'] };
var bob = {name: 'Bob', stapler: true, friends: [] };
console.log(objectHash(peter));
console.log(objectHash(michael));
console.log(objectHash(bob));
console.log(objectHash(peter, { excludeValues: true }));
console.log(objectHash(michael, { excludeValues: true }));
console.log(objectHash(bob, { excludeValues: true }));
console.log(objectHash(peter, { algorithm: 'md5', encoding: 'base64' }));
console.log(objectHash(michael, { algorithm: 'md5', encoding: 'base64' }));
console.log(objectHash(bob, { algorithm: 'md5', encoding: 'base64' }));
Options
{
algorithm: '<sha1(default)|sha|md5|...>',
encoding: '<hex(default)|buffer|binary|base64>',
excludeValues: <false(default)|true>
}
Development
// if tape is installed globally
tape test
-or-
// if not
npm test
License
MIT