SkeLLLa/node-object-hash

disable sorting of arrays

adrian-gierakowski opened this issue · 6 comments

I'd like to be able to disable the sorting of arrays, so that hash([1,2] != hash([2,1]), while keeping all other "object" types sorted. Is this currently possible?

Hi. Currently it's not supported. But I think it's easy to add such option.
For example object sorter could consume not only boolean, but also an object that will define granular sorting behaviour for needed types that are used in stringifier.* methods.

It would be non-breaking change, and quiet easy to implement. If you would like to submit a PR, you're welcome. If not, I think I could find some time by the next weekend to add this.

thanks, I've added a sortArrays option on my fork for now, which I set to false to get my desired behaviour, cause that was the quickest way to get what I wanted. But I'll try to submit a PR with your what you've suggested if I find some time later this week.

If you still interested I've implemented granular sorting control options. The changes aren't published yet, but you may preview them in https://github.com/SkeLLLa/node-object-hash/tree/next branch.

Now it will add possibility to control what kind of items you need to sort. Also it allows to disable type coercion(https://github.com/SkeLLLa/node-object-hash/blob/next/docs/interfaces/objectsorter.coerceoptions.md).

I think it will be released in near future (~ in a week I think). But that would be v2.0.0.

Released in v2.0.0. Feel free to test and reopen if it doesn't work as expected.