Variadic deep recursive merge of objects
npm install @beenhere4hours/merge-objects
merge-objects
=====
Variadic deep recursive merge of objects
npm i @beenhere4hours/merge-objects``
const mergeObjects = require("@beenhere4hours/merge-objects").mergeObjects
const object1 = {firstName: "John", lastName: "Doe", address: {street: "123 Main St", city: "Youngstown"}};
const object2 = {id: "1234567890", address: {state: "OH", zip: 44504}};
const object3 = {attributes: {dob: "01-01-76", hair: "brown", eyes: "brown"}};
// can accept a variable number of parameters, so add as many as you'd like
mergeObjects(object1, object2, object3);
/*
expected result
{
address: {street: "123 Main St", city: "Youngstown", state: "OH", zip: 44504},
attributes: {dob: "01-01-76", hair: "brown", eyes: "brown"},
firstName: "John",
lastName: "Doe",
id: "1234567890"
};
*/
`
const mergeObjects = require("@beenhere4hours/merge-objects").mergeObjectsconst original = {firstName: "John", lastName: "Doe", address: {street: "123 Main St", city: "Youngstown"}};
// pass in an object literal as the first param or target
let copy = mergeObjects({}, original);
`Tests
npm test`