Nobody Pays (for) Magazines
Have ideas to improve npm?Join in the discussion! »

mergeTypeScript icon, indicating that this package has built-in type declarations

2.1.0 • Public • Published

Merge

(recursive)? merging of (cloned)? objects.

Install

Node.js

npm i merge
import merge from 'merge'

Browser

<script src="https://cdn.jsdelivr.net/gh/yeikos/js.merge/dist/merge.browser.min.js"></script>
window.merge

API

merge(cloneboolean, ...itemsObject[])
merge(...itemsObject[])
merge.recursive(cloneboolean, ...itemsObject[])
merge.recursive(...itemsObject[])

Examples

 
// Merge 
 
{
    var objectA = {} 
 
    merge(objectA, 
        { value: 1 }, 
        { str: 'hello world' }
    )
 
    var objectB = merge(true, objectA, 
        { value: 2 }
    )
 
    objectA // { value: 1, str: 'hello world' }
    objectB // { value: 2, str: 'hello world' }
}
 
// Recursive merge
 
{
    var objectA = {}
 
    merge.recursive(objectA, 
        { level: { value: 1 } },
        { level: { str: 'hello world' } }
    )
    var objectB = merge.recursive(true, objectA, 
        { level: { value: 2 } }
    )
 
    objectA.level // { value: 1, str: 'hello world' }
    objectB.level // { value: 2, str: 'hello world' }
}

Test

Node.js

npm test

Browser

./dist/merge.browser.test.html

Install

npm i merge

DownloadsWeekly Downloads

1,903,358

Version

2.1.0

License

MIT

Unpacked Size

6.88 kB

Total Files

5

Last publish

Collaborators

  • avatar