{"library":"object-hash","title":"Object Hash Generator","description":"object-hash is a JavaScript library designed to generate consistent hashes from various JavaScript objects and primitive values in both Node.js and browser environments. It leverages Node.js's built-in `crypto` module for hashing algorithms like SHA1 (default), MD5, and others available via `crypto.getHashes()`, as well as supporting custom stream processing. The current stable version is 3.0.0. A key aspect of its API contract, established since version 1.1.8 (April 2017), is that any changes affecting the exact returned hash value are considered `semver-major`, ensuring predictability for users. It differentiates itself by offering extensive configuration options, including the ability to ignore values, sort arrays/objects/sets for order-independent hashing, and respect or ignore function properties, making it highly flexible for use cases like caching, deduplication, or content addressing where object state needs to be consistently fingerprinted. It is important to note that default algorithms like SHA-1 and MD5 are not considered cryptographically secure and should not be used for security-sensitive applications.","language":"javascript","status":"active","last_verified":"Sun Apr 19","install":{"commands":["npm install object-hash"],"cli":null},"imports":["import hash from 'object-hash';","const hash = require('object-hash');","const hash = require('object-hash');\nconst myHash = hash.sha1({ a: 1 });"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"const hash = require('object-hash');\n\n// Basic hashing of an object\nconst objectHash = hash({ foo: 'bar', baz: [1, 2, { a: 3 }] });\nconsole.log('Object Hash:', objectHash); // Example: '37a3c3d5e21d5a7b6c7a9f8d9b6e2d1f0a8c4b2e'\n\n// Hashing with specific algorithm and encoding (e.g., SHA256)\nconst sha256Hash = hash({ data: 'sensitive info' }, { algorithm: 'sha256', encoding: 'base64' });\nconsole.log('SHA256 Hash (Base64):', sha256Hash);\n\n// Hashing an object, ignoring values (only keys contribute to hash)\nconst keysOnlyHash = hash({ name: 'Alice', age: 30 }, { excludeValues: true });\nconsole.log('Keys-only Hash:', keysOnlyHash);\n\n// Hashing with unordered objects and arrays for consistent results regardless of property/element order\nconst unorderedHash1 = hash({ x: 1, y: 2 }, { unorderedObjects: true, unorderedArrays: true });\nconst unorderedHash2 = hash({ y: 2, x: 1 }, { unorderedObjects: true, unorderedArrays: true });\nconsole.log('Unordered Object Hash 1:', unorderedHash1);\nconsole.log('Unordered Object Hash 2:', unorderedHash2);\nconsole.log('Unordered hashes match:', unorderedHash1 === unorderedHash2);\n","lang":"javascript","description":"Demonstrates basic object hashing, specifying a different algorithm and encoding, hashing only object keys, and ensuring order-independent hashing for objects and arrays.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}