You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
*Can reject to copy null value by option `{ rejectNull: true }`:
105
+
*If a value of source property is undefined (when not using converter), or a result of converter is undefined (when using converter), the value is not copied.
106
106
107
107
```js
108
-
var src = { a: 8, b: { c: -1, d: null } };
109
-
var dst = { a: 1, b: { c: 2, e: 4 } };
110
-
111
-
copyProps(src, dst, function(v) {
112
-
return (typeof v !== 'number' || v < 0) ? null : v;
113
-
}, { rejectNull: true });
114
-
// => { a: 8, b: { c: 2, e: 4 } }
115
-
```
116
-
117
-
***This `opts` must be passed at the place of the 4rd argument or later.***
118
-
119
-
So, when you use the `opts` and don't use neither `fromToProps` nor `converter`, write the code as follows:
If *fromToProps* is given, it is able to copy between different properties.
127
+
If *fromto* is given, it is able to copy between different properties.
136
128
If *converter* is given, it is able to convert the terminal values.
137
129
138
130
***Arguments:**
139
131
140
132
***src** [object] : a source object of copy.
141
133
***dst** [object] : a destinate object of copy.
142
-
* **fromToProps** [object | array] : an object mapping properties between *src* and *dst*. (optional)
134
+
***fromto** [object | array] : an object mapping properties between *src* and *dst*. (optional)
143
135
***converter** [function] : a function to convert terminal values in *src*. (optional)
144
-
* **opts** [object] : an option object which specifys copy's behaviors (optional)
136
+
* **reverse** [boolean] : copys reversively from dst to src and returns src object. `fromto` is also reversively used from value to key. This default value is `false`. (optional)
145
137
146
138
* **Return** [object] : *dst* object after copying.
147
139
148
-
#### *Format offromToProps*
140
+
#### *Format of fromto*
149
141
150
-
*fromToProps* is a non-nested key-value object. And the *key*s are property key chains of*src* and the *value*s are property key chains of*dst*.
142
+
*fromto* is a non-nested key-value object. And the *key*s are property key chains of *src* and the *value*s are property key chains of *dst*.
151
143
The key chain is a string which is concatenated property keys on each level with dots, like `'aaa.bbb.ccc'`.
152
144
153
145
The following example copys the value of `src.aaa.bbb.ccc` to `dst.xxx.yyy`.
@@ -158,29 +150,21 @@ copyProps(src, dst, {
158
150
})
159
151
```
160
152
161
-
*fromToProps* can be an array. In that case, the array works as a map which has pairs of same key and value.
153
+
*fromto* can be an array. In that case, the array works as a map which has pairs of same key and value.
162
154
163
155
#### *API of converter*
164
156
165
-
**<u>converter(value, keyChain) => any</u>**
157
+
**<u>converter(value, keychain) => any</u>**
166
158
167
159
*converter* is a function to convert terminal values of propeerties of *src*.
168
160
169
161
***Arguments:**
170
162
171
163
***value**[any] : a property value to be converted.
172
-
* **keyChain** [string] : a string of property keys concatenated with dots.
164
+
***keychain**[string] : a string of property keys concatenated with dots.
173
165
174
166
***Return:**[any] : converted value.
175
167
176
-
#### *Properties of opts*
177
-
178
-
*opts* can have following properties:
179
-
180
-
* **reverse** [boolean] : Copys reversively from *dst* to *src* and returns *src* object. *fromToProps* is also reversively used from value to key. This default value is `false`.
181
-
* **rejectNull** [boolean] : if this option is `true`, a value of a source object or a return value of *converter* is not copied when the value is null. The default value is `true`.
0 commit comments