Socket
Socket
Sign inDemoInstall

deterministic-object-hash

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

deterministic-object-hash

A deterministic object hashing algorithm for Node.js.


Version published
Maintainers
1
Created

What is deterministic-object-hash?

The deterministic-object-hash npm package is used to create consistent and deterministic hashes for JavaScript objects. This is particularly useful for scenarios where you need to ensure that the same object always produces the same hash, regardless of the order of its properties.

What are deterministic-object-hash's main functionalities?

Basic Hashing

This feature allows you to generate a deterministic hash for a given object. The order of properties in the object does not affect the hash value.

const deterministicHash = require('deterministic-object-hash');
const obj = { b: 2, a: 1 };
const hash = deterministicHash(obj);
console.log(hash);

Custom Hashing Algorithm

This feature allows you to specify a custom hashing algorithm. In this example, the 'sha256' algorithm is used to generate the hash.

const deterministicHash = require('deterministic-object-hash');
const obj = { b: 2, a: 1 };
const options = { algorithm: 'sha256' };
const hash = deterministicHash(obj, options);
console.log(hash);

Hashing with Custom Sort Function

This feature allows you to provide a custom sort function to determine the order of properties before hashing. This can be useful for more complex sorting requirements.

const deterministicHash = require('deterministic-object-hash');
const obj = { b: 2, a: 1 };
const options = { sort: (a, b) => a.localeCompare(b) };
const hash = deterministicHash(obj, options);
console.log(hash);

Other packages similar to deterministic-object-hash

Keywords

FAQs

Package last updated on 20 Nov 2023

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