Skip to content
This repository has been archived by the owner on Apr 1, 2023. It is now read-only.

Latest commit

 

History

History
79 lines (67 loc) · 2.43 KB

superimpose.md

File metadata and controls

79 lines (67 loc) · 2.43 KB

Object Agent

A javascript library for working with objects

npm build coverage deps size vulnerabilities license


superimpose(args, [mutateFirst]) ⇒ *

Deeply superimposes two or more items on each other.

Notes:

  • Undefined values will not overwrite defined values
  • Array order is maintained

Returns: * - The resulting object

Param Type Default Description
args * two or more items to superimpose on each other. Each item is superimposed on the item before it.
[mutateFirst] Boolean false If a final argument of true is provided, then the first object will be mutated in place and returned.

Example

import { superimpose } from 'object-agent';

const thing1 = {
    a: 1,
    c: {
        d: 3
        e: 5
    },
    f: [1, 2]
};

const thing2 = {
    b: 2,
    c: {
        d: 4
    },
    f: [3]
};

const result = superimpose(thing1, thing2);
// => {
//	a: 1,
//	b: 2,
//	c: {
//		d: 4,
//		e: 5
//	},
//	f: [3, 2]
//}

console.log(result === thing1);
// => false