@zhelvis/structure-ts
    Preparing search index...

    Function applyDiff

    • 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.

      Parameters

      • target: unknown

        The object to apply changes to (will not be modified)

      • diff: Diff

        Array of actions representing the changes to apply

      Returns unknown

      A new object with all the changes applied

      When navigation fails or invalid operations are attempted

      When unknown action types are encountered

      When prototype pollution is detected

      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)