benjamine / jsondiffpatch

Diff & patch JavaScript objects
MIT License
4.83k stars 472 forks source link

Exclude object form array for diff #286

Open unandyala opened 4 years ago

unandyala commented 4 years ago

Hi Benjamine,

Thank you for the awesome library. I have a question related to arrays

I have array of objects. I want to exclude some of the objects based on the key - something like if key ends with number don't compare (exclude from diffing). Is that possible with plugins? If so where should it placed in the filters? sample json:

[
  {
    "key": "A",
    "p1": "p1"
  },
  {
    "key": "B",
    "p1": "p1"
  },
  {
    "key": "A123",
    "p1": "p1",
    "p2": "p2"
  }
]

I want exclude object with key "A123" when doing diff

Thanks

prasanmgc commented 2 years ago

Haven't tried but you can do something like this using propertyFilter option. const diffpatcher = create({ propertyFilter: (obj: any, name: string) => obj.name !== "A123", }); const diff = diffpatcher.diff(expectedJson, actualJson);