Coder Social home page Coder Social logo

hash-obj's Introduction

hash-object

Get the hash of an object

Install

npm install hash-object

Usage

import hashObject from 'hash-object';

hashObject({'๐Ÿฆ„': '๐ŸŒˆ'}, {algorithm: 'sha1'});
//=> '3de3bc784035b559784fc276f47493d60555fba3'

API

hashObject(object, options?)

The output is deterministic for repeated runs on the same Node.js / browser version. It should also be fairly deterministic across JavaScript engines. However, because the stability of grapheme clusters across Unicode versions is not guaranteed, determinism cannot be guaranteed across JavaScript engines and versions. There are also other factors that can make it nondeterministic, like values with floating point numbers and dates.

object

Type: object

options

Type: object

encoding

Type: 'hex' | 'base64' | 'buffer' | 'latin1'
Default: 'hex'

The encoding of the returned hash.

algorithm

Type: string
Default: 'sha512'
Values: 'md5' | 'sha1' | 'sha256' | 'sha512' | โ€ฆ (Platform dependent)

Don't use 'md5' or 'sha1' for anything sensitive. They're insecure.

Related

  • hasha - Hashing made simple. Get the hash of a buffer/string/stream/file.

hash-obj's People

Contributors

bendingbender avatar richienb avatar sindresorhus avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

hash-obj's Issues

Is this deterministic?

Is hash-obj deterministic across any environment?

I see it uses sort-keys, so I guess it's deterministic, but just asking to make sure.

If so, I think it'd be better to advertise the determinism on the readme.

Thanks.

Handling Circular References in `hashObject` Function

When the hashObject function encounters circular references in the input object, it currently leads to a "maximum call stack size exceeded" error due to an infinite loop during the normalization process. This issue can result in unexpected behavior and a lack of graceful error handling for users.

Steps to Reproduce:

const obj = { a: { b: {} } };
obj.a.b = obj; // Creating a circular reference
const hash = hashObject(obj, { algorithm: 'sha1' });
console.log(hash);
//=> Error: Maximum call stack size exceeded

Proposed Solution:

Implement a mechanism within the hashObject function to detect circular references and handle them gracefully. Upon encountering a circular reference, the function should throw a specific error message informing users about the issue.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.