UNPKG

1.04 kBJavaScriptView Raw
1import assignValue from './_assignValue.js';
2import baseAssignValue from './_baseAssignValue.js';
3
4/**
5 * Copies properties of `source` to `object`.
6 *
7 * @private
8 * @param {Object} source The object to copy properties from.
9 * @param {Array} props The property identifiers to copy.
10 * @param {Object} [object={}] The object to copy properties to.
11 * @param {Function} [customizer] The function to customize copied values.
12 * @returns {Object} Returns `object`.
13 */
14function copyObject(source, props, object, customizer) {
15 var isNew = !object;
16 object || (object = {});
17
18 var index = -1,
19 length = props.length;
20
21 while (++index < length) {
22 var key = props[index];
23
24 var newValue = customizer
25 ? customizer(object[key], source[key], key, object, source)
26 : undefined;
27
28 if (newValue === undefined) {
29 newValue = source[key];
30 }
31 if (isNew) {
32 baseAssignValue(object, key, newValue);
33 } else {
34 assignValue(object, key, newValue);
35 }
36 }
37 return object;
38}
39
40export default copyObject;