UNPKG

1.21 kBMarkdownView Raw
1# Merge
2
3(recursive)? merging of (cloned)? objects.
4
5# Install
6
7## Node.js
8
9```sh
10npm i merge
11```
12```js
13import merge from 'merge'
14```
15
16## Browser
17
18```html
19<script src="https://cdn.jsdelivr.net/gh/yeikos/js.merge/dist/merge.browser.min.js"></script>
20```
21```js
22window.merge
23```
24
25# API
26
27```typescript
28merge(clone: boolean, ...items: Object[])
29merge(...items: Object[])
30merge.recursive(clone: boolean, ...items: Object[])
31merge.recursive(...items: Object[])
32```
33
34# Examples
35
36```js
37
38// Merge
39
40{
41 var objectA = {}
42
43 merge(objectA,
44 { value: 1 },
45 { str: 'hello world' }
46 )
47
48 var objectB = merge(true, objectA,
49 { value: 2 }
50 )
51
52 objectA // { value: 1, str: 'hello world' }
53 objectB // { value: 2, str: 'hello world' }
54}
55
56// Recursive merge
57
58{
59 var objectA = {}
60
61 merge.recursive(objectA,
62 { level: { value: 1 } },
63 { level: { str: 'hello world' } }
64 )
65 var objectB = merge.recursive(true, objectA,
66 { level: { value: 2 } }
67 )
68
69 objectA.level // { value: 1, str: 'hello world' }
70 objectB.level // { value: 2, str: 'hello world' }
71}
72```
73# Test
74
75## Node.js
76
77```sh
78npm test
79```
80## Browser
81
82```
83./dist/merge.browser.test.html
84```
\No newline at end of file