The object to apply changes to (will not be modified)
Array of actions representing the changes to apply
A new object with all the changes applied
const original = { a: 1, b: { c: 2 } };
const changes = [
{ type: ActionType.CHANGE, path: ['b', 'c'], from: 2, to: 3 },
{ type: ActionType.ADD, path: ['d'], value: 4 }
];
const result = applyDiff(original, changes);
// result: { a: 1, b: { c: 3 }, d: 4 }
// original: { a: 1, b: { c: 2 } } (unchanged)
Applies a series of diff actions to a target object, creating a new modified version.
This function takes a target object and a series of actions, then applies each action in sequence to create a transformed version of the target. The original target is not modified - a deep clone is created first.