jsondiffpatch.net icon indicating copy to clipboard operation
jsondiffpatch.net copied to clipboard

Case sensitivity and order while comparing values

Open chetanmotamarri opened this issue 5 years ago • 2 comments

  1. Is there any way in this library to ignore cases while comparing ?
  2. Also to ignore the order of values in array

Example: array1 = [ "Audi", "toyota", "merc"]; array2 = [ "toyota", "audi", "merc"];

output: It should treat both array1 and array2 as same (as they have same values in different order and different cases i.e. capital and lowercases)

chetanmotamarri avatar Apr 03 '19 23:04 chetanmotamarri

Any update on this one ?

chetanmotamarri avatar Apr 19 '19 18:04 chetanmotamarri

No, feel free to add these features and submit a PR. Unfortunately, I don't have time to work on these.

For the first one I think maybe the right approach would be to expose an comparer interface people can implement and pass into JsonDiffPatch -- that way we can support weird cases like (int)1 == (string)"1"

The second one exists in the original JsonDiffPatch library already and something we should definitely add. Search for "detectMove" in benjamine/jsondiffpatch (https://github.com/benjamine/jsondiffpatch/blob/0c4323e9bff23ae231f4bff231ceed4df2b48be5/src/filters/arrays.js#L192)

wbish avatar Apr 19 '19 18:04 wbish