🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more

object-hash

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install
o

object-hash

Generate hashes from javascript objects in node and the browser.

3.0.0
latest
100

Supply Chain Security

100

Vulnerability

100

Quality

79

Maintenance

100

License

Version published
Weekly downloads
28M
2.94%
Maintainers
2
Weekly downloads
 
Created
Issues
40

What is object-hash?

The object-hash npm package provides a function to generate a hash from a JavaScript object using various algorithms. It is useful for creating unique identifiers for objects, comparing objects by their hash, and caching objects based on their content.

What are object-hash's main functionalities?

Generate hash from an object

This feature allows you to generate a hash string from a JavaScript object. The hash is determined by the object's content.

const hash = require('object-hash');
const myObject = { name: 'Alice', age: 25 };
const objectHash = hash(myObject);

Generate hash with different algorithms

This feature allows you to specify different hashing algorithms, such as 'md5', 'sha1', 'sha256', etc., to generate the hash.

const hash = require('object-hash');
const options = { algorithm: 'sha256' };
const objectHash = hash({ name: 'Alice', age: 25 }, options);

Exclude properties from hashing

This feature allows you to exclude the values of the properties from the hash, effectively hashing the structure (keys) of the object only.

const hash = require('object-hash');
const options = { excludeValues: true };
const objectHash = hash({ name: 'Alice', age: 25 }, options);

Respect object types

This feature allows you to ignore the type of the object when generating the hash, treating arrays and objects with the same content as equal.

const hash = require('object-hash');
const options = { respectType: false };
const objectHash = hash([1, 2, 3], options);

Other packages similar to object-hash

FAQs

Package last updated on 18 Feb 2022

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