@ianwalter/merge

9.0.1 • Public • Published

@ianwalter/merge

Recursively merge JavaScript Objects

npm page CI

About

Inspired by and created as an alternative for deepmerge.

Usage

import merge from '@ianwalter/merge'

const item1 = { id: 1, details: { name: 'Civilian', lists: ['Folk'] } }
const item3 = { id: 2, details: { plays: 2 } }
const item2 = { id: 3, details: { lists: ['Chill', 'Alt'] } }

merge(item1, item2, item3) //=> {
//    id: 3,
//    details: {
//      name: 'Civilian',
//      plays: 2,
//      lists: ['Chill', 'Alt']
//    }
//  }

Note

Like Object.assign, merge will treat the first passed item as the "destination" and mutate it. If you want a new "destination" object simply pass an empty object {} as the first argument or you can always use @ianwalter/clone and clone the first argument beforehand. merge will also merge prototype properties of objects so if you don't want that you can also use clone to clone your objects before merging them since, with the default options, clone does not clone prototype properties.

Related

  • @ianwalter/clone - A configurable utility to clone JavaScript data (Objects, Arrays, etc)

License

Apache 2.0 with Commons Clause - See LICENSE

 

Created by Ian Walter

Package Sidebar

Install

npm i @ianwalter/merge

Weekly Downloads

152

Version

9.0.1

License

SEE LICENSE IN LICENSE

Unpacked Size

6.86 kB

Total Files

7

Last publish

Collaborators

  • ianwalter