1 | # Merge
|
2 |
|
3 | (recursive)? merging of (cloned)? objects.
|
4 |
|
5 | # Install
|
6 |
|
7 | ## Node.js
|
8 |
|
9 | ```sh
|
10 | npm i merge
|
11 | ```
|
12 | ```js
|
13 | import 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
|
22 | window.merge
|
23 | ```
|
24 |
|
25 | # API
|
26 |
|
27 | ```typescript
|
28 | merge(clone: boolean, ...items: Object[])
|
29 | merge(...items: Object[])
|
30 | merge.recursive(clone: boolean, ...items: Object[])
|
31 | merge.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
|
78 | npm test
|
79 | ```
|
80 | ## Browser
|
81 |
|
82 | ```
|
83 | ./dist/merge.browser.test.html
|
84 | ``` |
\ | No newline at end of file |