1.0.1 • Published 9 months ago

mrgr v1.0.1

Weekly downloads
-
License
ISC
Repository
-
Last release
9 months ago

README

Mrgr merges any number of javascript objects into one, adhering to the options you specify. Input objects remain unchanged.

Usage

import Mrgr from 'mrgr'

/* Objects to merge */

const a = {
  lorem: "ipsum",
  dolor: {
    sit: "amet",
    consectetur: "adipiscing"
  }
}

const b = {
  dolor: {
    sit: "hello, world!"
  },
  foo: "bar"
}

const c = {
  hello: "world"
}

/* Specify options */

const options = { saveAdditionalKeys: true }

/* Merge */

const mrgr = new Mrgr()
const merged = mrgr
  .changeOptions(options)
  .merge(a, b, c)

console.log(merged)

// {
//  lorem: "ipsum",
//  dolor: {
//    sit: "hello, world!",
//    consectetur: "adipiscing"
//  },
//  foo: "bar",
//  hello: "world"
// }

Options

saveAdditionalKeys: boolean

default: false

If set to false, the first object passed to merge() will be treated as a template object. Only the properties set on that first object will be present in the returned object.

If set to true, any properties not present in the first, but only in objects thereafter, will be copied to the returned object.

1.0.1

9 months ago

1.0.0

9 months ago