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

Usage #20

Closed
mrjjwright opened this issue Aug 26, 2019 · 3 comments
Closed

Usage #20

mrjjwright opened this issue Aug 26, 2019 · 3 comments

Comments

@mrjjwright
Copy link

I am sorry if this comes off as a dumb question but what are some of examples of what you could use this library to do? I have entertained the idea of hashing my objects into a history tree, similar to git and things like that. I was curious what others actually use this for.

@mrjjwright
Copy link
Author

Also great performance work!

@SkeLLLa
Copy link
Owner

SkeLLLa commented Aug 27, 2019

@mrjjwright this library mostly used to check unique object values. In javascript simple JSON.stringify will not guarantee the order of object key-value pairs. Also you may have arrays with identical contents, but placed in different order, e.g. [1,2] and [2,1]. So this lib performs sorting of such different js object types. Then it transforms all the staff to some string representation and optionally calculates hash of this representation to get small sized hash. Also this lib optionally can perform coercion, e.g. if you have data like {isActive: 1} and other {isActive: true} those can have identical hashes.

For example it's useful if you have different sources of data and you want to ensure that there will be no duplicates in your database, you may calculate hash, add such field into your document and check if it's unique. And if it's not you may perform something like merge doc, or overwrite.

Also it can be used for cache. Some dependents of this library as far as I know are kind of webpack plugins and they calculate hash of files metadata in order to check if file already being built.

@mrjjwright
Copy link
Author

Thanks for this helpful overview!

@SkeLLLa SkeLLLa pinned this issue Aug 27, 2019
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