@nevware21/ts-utils
    Preparing search index...

    Function objDiff

    • Returns a shallow diff of two objects: a new object containing only the own enumerable properties from modified whose values differ from the corresponding values in base (using strict equality !==). Properties present in modified but not in base are also included. Properties removed in modified (i.e. present only in base) are not included — use the result to describe what changed in modified.

      Type Parameters

      • T

        The type of the base object

      • U extends Partial<T> = Partial<T>

        The type of the modified object (defaults to Partial<T>)

      Parameters

      • base: T

        The original / reference object

      • modified: U

        The updated object to compare against base

      Returns Partial<U>

      A new plain object with the keys from modified that differ from base. Returns an empty object when the two objects are equivalent or when either argument is null or undefined.

      0.14.0

      const prev = { x: 1, y: 2, z: 3 };
      const next = { x: 1, y: 99, z: 3 };

      objDiff(prev, next); // { y: 99 }

      // Added keys are included
      objDiff({ a: 1 }, { a: 1, b: 2 }); // { b: 2 }

      // Removed keys are NOT included
      objDiff({ a: 1, b: 2 }, { a: 1 }); // {}

      // null / undefined values are compared strictly
      objDiff({ a: null }, { a: undefined }); // { a: undefined }