Giter Club home page Giter Club logo

hash-it's People

Contributors

dependabot[bot] avatar jorgenevens avatar planttheidea avatar ykou 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

hash-it's Issues

When is this useful ?

Hi when am I supposed to use it ? From the example code, I assume that objects that have same set of key/ value will produce same hash, so it's quite of verification stuff ?

Handling undefined keys

We're using hash-it to compute cache keys and ran into situations where objects to be hashed look like this

  1. { a: 1, b: undefined }
  2. { a: 1 }

We can pass it through JSON.stringify() beforehand locally but it would be better if this utility would handle that

So is there any way to exclude object keys where their value is undefined?

Multiple issues with the encoding

The encoding used by hash-it a) makes it trivial to generate collisions (cf.), b) doesn't handle nested dates, and c) doesn't distinguish between different circular references:

import hash from 'hash-it'
    
hash.is(42, "number|42")   // true 
hash.is(null, "null|null") // true 

hash.is(new Date(1970, 0, 1), "Date|0")                                       // true
hash.is(new Date(1970, 0, 1), "1970-01-01T00:00:00.000Z")                     // false
hash.is({ date: new Date(1970, 0, 1) }, { date: "1970-01-01T00:00:00.000Z" }) // true

obj = {}
obj.self = obj
    
hash.is(obj, { "self": "~" }) // true 

arr1 = [obj, obj, obj]
arr2 = [obj, obj]
arr2.push(arr2) 

hash.is(arr1, '[{"self":"~"},"~","~"]') // true
hash.is(arr1, arr2)                     // true

These can be worked around with a more consistent/robust encoding, e.g. nested dates can be detected via this[key] instanceof Date, and strings can be distinguished from other primitives by (always) using a prefix, e.g. "string|Hello, world!".

I haven't used it, but it looks like (your :-) fast-stringify provides a path parameter which can be used to distinguish between the different circular references.

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.