1.0.16 • Published 5 years ago

@beenhere4hours/merge-objects v1.0.16

Weekly downloads
22
License
MIT
Repository
github
Last release
5 years ago

Build Status

merge-objects

Variadic deep recursive merge of objects

Installation

npm i @beenhere4hours/merge-objects

Usage

merge multiple 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"
};
*/

deep copy object

Create a new, deep copy, of an object that has the same properties and values, but is not the same object.

const mergeObjects = require("@beenhere4hours/merge-objects").mergeObjects

const 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

1.0.16

5 years ago

1.0.15

5 years ago

1.0.14

5 years ago

1.0.13

5 years ago

1.0.12

5 years ago

1.0.11

5 years ago

1.0.10

5 years ago

1.0.7

5 years ago

1.0.6

5 years ago

1.0.5

5 years ago

1.0.4

5 years ago

1.0.3

5 years ago

1.0.2

5 years ago

1.0.1

5 years ago

1.0.0

5 years ago