cosmicanant / recursive-diff

A JavaScript library to find diff between two JavaScript Objects. Support for Array, Number, Date and other primitive data types.
MIT License
144 stars 22 forks source link

[Question] Diff ignoring "nullish" values #49

Open JSEvgeny opened 8 months ago

JSEvgeny commented 8 months ago

Hey there I hope you are doing great,

I was wondering if there is a away to ignore fields that have nullish values when diffing?

The use-case could be having, let's say, some value as undefined in the source object, but empty string or empty array for the same field in target (transformer may have converted undefined values to empty/nullish) and I would like not to consider these as a change for specific property, but ignore it from changes object.

Thank you in advance and have a great day 🙌

cosmicanant commented 8 months ago

Hey, thanks for reaching out. This feature doesn't exist at the moment. Probably a custom comparator function we can take to customize the target diff. A workaround would be to traverse the diff object and deleting the values having nullish update. You can utilize keepOldValueInDiff parameter so that old value is also there in the diff object.