@@ -69,21 +69,55 @@ Usage
69
69
// => { a: 2, b: { b1: 'BBB' } }
70
70
```
71
71
72
+ * Can use an array instead of a map as property mapping :
73
+
74
+ ` ` ` js
75
+ var src = { a: 1, b: { c: 'CCC' }, d: { e: 'EEE' } };
76
+ var dst = { a: 9, b: { c: 'xxx' }, d: { e: 'yyy' } };
77
+ var fromToProps = [ 'a.b.c', 'd.e' ];
78
+ copyProps(src, dst, fromToProps);
79
+ // => { a: 1, b: { c: 'CCC' }, d: { e: 'EEE' } }
80
+ ` ` `
81
+
82
+ * Can copy reversively (from * dst* to * src* ) by boolean flag :
83
+
84
+ ` ` ` js
85
+ var src = { a: 1, b: { b1: 'bbb' }, c: 'ccc' };
86
+ var dst = { a: 2, b: { b1: 'xxx', b2: 'yyy' } };
87
+
88
+ copyProps(src, dst, true);
89
+ // => { a: 2, b: { b1: 'xxx', b2: 'yyy' }, c: 'ccc' }
90
+ ` ` `
91
+
92
+ ` ` ` js
93
+ var src = { a: 1, b: { b1: 'bbb' }, c: 'ccc', d: 'ddd' };
94
+ var dst = { f: { a: 2, b1: 'xxx', b2: 'yyy' }, e: 'zzz' };
95
+
96
+ copyProps(src, dst, {
97
+ a: 'f.a',
98
+ 'b.b1': 'f.b1',
99
+ 'b.b2': 'f.b2',
100
+ 'c': 'f.c',
101
+ }, true);
102
+ // => { a: 2, b: { b1: 'bbb', b2: 'yyy' }, c: 'ccc', d: 'ddd' }
103
+ ` ` `
104
+
72
105
API
73
106
-- -
74
107
75
- ### < u> copyProps (src, dst [, fromToProps] [, converter]) => object< / u>
108
+ ### < u> copyProps (src, dst [, fromToProps] [, converter] [, isReversed] ) => object< / u>
76
109
77
110
Copy properties of * src* to * dst* deeply.
78
- If * map * is given, it is able to copy between different properties.
111
+ If * fromToProps * is given, it is able to copy between different properties.
79
112
If * converter* is given, it is able to convert the terminal values.
80
113
81
114
* ** Arguments: **
82
115
83
116
* ** src** [object] : a source object of copy.
84
117
* ** dst** [object] : a destinate object of copy.
85
- * ** fromToProps** [object] : an object mapping properties between * src* and * dst* .
86
- * ** converter** [function ] : a function to convert terminal values in *src*.
118
+ * ** fromToProps** [object | array] : an object mapping properties between * src* and * dst* . (optional)
119
+ * ** converter** [function ] : a function to convert terminal values in *src*. (optional )
120
+ * **isReversed** [boolean] : a flag to copy reversively. (optional)
87
121
88
122
* **Return** [object] : *dst* object after copying.
89
123
@@ -100,6 +134,8 @@ copyProps(src, dst, {
100
134
})
101
135
```
102
136
137
+ * fromToProps* can be an array. In that case, the array works as a map which has pairs of same key and value.
138
+
103
139
#### API of * converter*
104
140
105
141
** <u >converter(value, keyChain) => any</u >**
0 commit comments