Open borriglione opened 3 months ago
Thank you for opening an issue and using my library!
I tried to reproduce the problem but already get a linter error when trying to call diff()
because objBefore
is not of type StringIndexableObject
. This originates in numbers
being not an object (to be exact, a StringIndexableObject
), but an array of numbers.
This seems to be a general problem, that diff()
only works on this special type of objects containing only StringIndexable
objects as attributes.
It seems possible to enhance the library to check for the actual type of each attribute and handle arrays as well. Would you like to create a PR for that? I would very much appreciate that!
Version 4.3.0 brings functionality to make diff
also work with arrays, as well as other functions like flatten
.
Your example should now return this:
{
"config": {
"numbers": [{
"decimalPlaces": undefined,
"unit": undefined,
"value": undefined
}],
},
}
This is not yet what I expected, because with from
there should the 1
be included. But the current mechanism to create the difference sees that the attributes of the object in numbers
don't exist in from
, so it sets them to undefined
, thereby overwriting the 1
.
I'm not quite sure how to solve this, but I thought even in this state it might be worth publishing the new version, because this is a rare edge case.
@jschirrmacher thank you for the update!