Package Exports
- @75lb/deep-merge
Readme
@75lb/deep-merge
Deep-merge the values of one object structure into another. Similar to Object.assign() except it processes the full depth of the object structure, not only the top level. Useful for merging config.
Synopsis
import deepMerge from '@75lb/deep-merge'
Simple
Typical example merging four objects. Input:
deepMerge(
{ port: 8000, data: { animal: 'cow' } },
{ stack: ['one'] },
{ stack: ['two'], help: true },
{ data: { animal: 'bat', metal: 'iron' } }
)Result
{
port: 8000,
stack: ['two'],
help: true,
data: { animal: 'bat', metal: 'iron' }
}Arrays
Empty arrays are ignored and not merged in. Input:
deepMerge(
{ stack: ['one'] },
{ stack: [] }
)Result:
{ stack: ['one'] }However, if the later array contains one or more values the later array will replace the original:
deepMerge(
{ stack: ['one'] },
{ stack: ['two'] }
)Result:
{ stack: ['two'] }© 2021 Lloyd Brookes <75pound@gmail.com>.
Tested by test-runner. Documented by jsdoc-to-markdown.