Skip to content

A tiny utility that merges JavaScript objects by bundling clashing property values.

Notifications You must be signed in to change notification settings

sarukuku/object-joiner

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

28 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

object-joiner

A tiny utility that merges JavaScript objects by bundling clashing property values to arrays instead of overwriting them. Variable number of objects can be passed as arguments.

Other details

  • Clashing arrays are merged and order of array items preserved
  • In objects when a cyclic reference is found it's replaced with a string containing [Cyclic]

Install

Install with npm:

$ npm install --save object-joiner

Usage

const joinObjects = require('object-joiner')

const x = {
  a: "a",
  b: {
    a: "a"
  }
}

const y = {
  b: {
    a: "b"
  },
  c: "c"
}

const result = joinObjects(x, y)

/*
> console.log(result)
> {
    a: "a",
    b: {
      a: ["a", "b"]
    },
    c: "c"
  }
* /

(see the index.test.js file for more examples)

About

A tiny utility that merges JavaScript objects by bundling clashing property values.

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published