• Update a source object by replacing its keys and values with those from a target object.

    Parameters

    • original: object

      The initial object which should be updated with values from the target

    • Optionalother: object = {}

      A new object whose values should replace those in the source

    • Optionaloptions: {
          enforceTypes?: boolean;
          inplace?: boolean;
          insertKeys?: boolean;
          insertValues?: boolean;
          overwrite?: boolean;
          performDeletions?: boolean;
          recursive?: boolean;
      } = {}

      Additional options which configure the merge

      • OptionalenforceTypes?: boolean

        Control whether strict type checking requires that the value of a key in the other object must match the data type in the original data to be merged.

      • Optionalinplace?: boolean

        Control whether to apply updates to the original object in-place (if true), otherwise the original object is duplicated and the copy is merged.

      • OptionalinsertKeys?: boolean

        Control whether to insert new top-level objects into the resulting structure which do not previously exist in the original object.

      • OptionalinsertValues?: boolean

        Control whether to insert new nested values into child objects in the resulting structure which did not previously exist in the original object.

      • Optionaloverwrite?: boolean

        Control whether to replace existing values in the source, or only merge values which do not already exist in the original object.

      • OptionalperformDeletions?: boolean

        Control whether to perform deletions on the original object if deletion keys are present in the other object.

      • Optionalrecursive?: boolean

        Control whether to merge inner-objects recursively (if true), or whether to simply replace inner objects with a provided new value.

    • Optional_d: number = 0

      A privately used parameter to track recursion depth.

    Returns object

    The original source object including updated, inserted, or overwritten records.

    mergeObject({k1: "v1"}, {k2: "v2"}, {insertKeys: false}); // {k1: "v1"}
    mergeObject({k1: "v1"}, {k2: "v2"}, {insertKeys: true}); // {k1: "v1", k2: "v2"}
    mergeObject({k1: {i1: "v1"}}, {k1: {i2: "v2"}}, {insertValues: false}); // {k1: {i1: "v1"}}
    mergeObject({k1: {i1: "v1"}}, {k1: {i2: "v2"}}, {insertValues: true}); // {k1: {i1: "v1", i2: "v2"}}
    mergeObject({k1: "v1"}, {k1: "v2"}, {overwrite: true}); // {k1: "v2"}
    mergeObject({k1: "v1"}, {k1: "v2"}, {overwrite: false}); // {k1: "v1"}
    mergeObject({k1: {i1: "v1"}}, {k1: {i2: "v2"}}, {recursive: false}); // {k1: {i2: "v2"}}
    mergeObject({k1: {i1: "v1"}}, {k1: {i2: "v2"}}, {recursive: true}); // {k1: {i1: "v1", i2: "v2"}}
    mergeObject({k1: "v1", k2: "v2"}, {"-=k1": null}, {performDeletions: true});   // {k2: "v2"}
    
    mergeObject({k1: {i1: "v1"}}, {"==k1": {i2: "v2"}}, {performDeletions: true}); // {k1: {i2: "v2"}}