Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Feature request: using excludeValues, don't exclude keys for for nested objects #40

Open
spiderbites opened this issue Nov 18, 2016 · 4 comments

Comments

@spiderbites
Copy link

Hello,

First off, thanks for this library! I'm interested using this library to determine whether two nested objects are structurally equal. In other words, I'd like to compare hashes computed with the excludeValues: true option, but that takes into account whether nested objects have the same keys.

e.g.

var baz = { 
  foo: {
    innerkey1: 'baz'
  }
}

var fizz = {  
  foo: {
    innerkey2: 'fizz'
  }
}

The current behaviour has hash(baz, {excludeValues: true}) === hash(fizz, {excludeValues: true}), but for my use case i need them to be not equal, since they have different nested keys.

If this is a use case this library would like to support I'd be interested in working on a PR for it.

Thanks

@addaleax
Copy link
Collaborator

@spiderbites Sorry for the late reply… maybe I’m misunderstanding you but would

hash(Object.values(baz)) !== hash(Object.values(fizz))

be what you want? If not… I am not a hundred percent sure what “structurally equal” means in this context?

@spiderbites
Copy link
Author

spiderbites commented Nov 22, 2016

No, that's not quite what I'm getting at. Another way to say it is that hash(obj1) === hash(obj2) if and only if all of the keys in obj1 appear in obj2, both top-level keys and any keys in nested objects.

@addaleax
Copy link
Collaborator

Oh – so, exclude each value in an object only if that value itself is not an object? Yeah, that seems to make sense, and you can definitely work on a PR if you’d like (or wait for me to do that).

@spiderbites
Copy link
Author

Yes that's exactly it. I'll try and find some time for that. Cheers!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants