object-hash
's direct dependencies. Data on all dependencies, including transitive ones, is available via CSV download.Name | Version | Size | License | Type | Vulnerabilities |
---|
Object-hash is a popular npm package designed to generate hashes from Javascript objects and values in both node and the browser. Under the hood, it uses the node.js crypto module for hashing functionality. It supports various hash algorithms, including SHA1, MD5 and others depending on the platform, as well as custom streams like CRC32. It's designed to accommodate hashing values of any type and allows for the exclusion of values, giving you the flexibility to generate hashes of keys only, thereby grouping similar objects with varying values.
Using object-hash is relatively straightforward. First, you need to install the package by running npm install object-hash
in your terminal. Once installed, you can generate a hash from an object or any other type by importing the module and calling the hash function. Here are some usage examples:
// Include the package in your file
var hash = require('object-hash');
// Generate a hash
hash({foo: 'bar'}) // Returns: '67b69634f9880a282c14a0f0cb7ba20cf5d677e9'
hash([1, 2, 2.718, 3.14159]) // Returns: '136b9b88375971dff9f1af09d7356e3e04281951'
You can leverage different algorithms and encodings and exclude values or keys:
hash({foo: 'bar', a: 42}, { respectType: false }) // e.g. 'object:anumber:42foo:string:bar'
The object-hash package comes with built-in sugar methods including hash.sha1(value)
, hash.keys(value)
, hash.MD5(value)
, and hash.keysMD5(value)
. For instance, hash.sha1(value)
is equivalent to hash(value, {algorithm: 'sha1'})
.
The detailed documentation for object-hash can be found on the project's GitHub page at https://github.com/puleos/object-hash
. Here, you'll find executive summaries of what the package does, how it works, and more detailed examples of how to use it based on a variety of scenarios and requirements. The readme file for the library is quite comprehensive, providing a reliable point of reference for understanding and utilizing the package effectively.