deep-object-diff
deep-object-diff copied to clipboard
Also return original values for deleted and updated? Feature request.
Hi Matt. Great package thanks.
Would you be able to create versions of deletedDiff, updatedDiff, detailedDiff
or have them accept an optional shouldShowOriginal
argument to also return the original values too? Eg:
const lhs = {
foo: {
bar: {
a: ['a', 'b'],
b: 2,
c: ['x', 'y'],
e: 100 // deleted
}
},
buzz: 'world'
};
const rhs = {
foo: {
bar: {
a: ['a'], // index 1 ('b') deleted
b: 2, // unchanged
c: ['x', 'y', 'z'], // 'z' added
d: 'Hello, world!' // added
}
},
buzz: 'fizz' // updated
};
console.log(detailedDiff(lhs, rhs, true));
/*
{
added: {
foo: {
bar: {
c: {
'2': 'z'
},
d: 'Hello, world!'
}
}
},
deleted: {
foo: {
bar: {
a: {
'1': undefined
},
e: undefined
}
}
},
deletedOriginal: {
foo: {
bar: {
a: ['a', 'b'],
e: 100
}
}
},
updated: {
buzz: 'fizz'
}
updatedOriginal: {
buzz: 'world'
}
}
*/
Obviously just showing detailedDiff
implementation but would be same for deletedDiff, updatedDiff
.
Thanks. Sean
@seanonthenet did you find a workaround or another package? I would like a similar feature. Thanks.
@guillett sorry, no
@guillett, @seanonthenet as a dirty workaround:
let results = datailedDiff(oldItem, newItem);
results.deletedOriginal = deletedDiff(results.deleted, oldItem);
results.updatedOriginal = updatedDiff(results.updated, oldItem);