1
|
var baseSet = require('./_baseSet');
|
2
|
|
3
|
/**
|
4
|
* This method is like `_.set` except that it accepts `customizer` which is
|
5
|
* invoked to produce the objects of `path`. If `customizer` returns `undefined`
|
6
|
* path creation is handled by the method instead. The `customizer` is invoked
|
7
|
* with three arguments: (nsValue, key, nsObject).
|
8
|
*
|
9
|
* **Note:** This method mutates `object`.
|
10
|
*
|
11
|
* @static
|
12
|
* @memberOf _
|
13
|
* @since 4.0.0
|
14
|
* @category Object
|
15
|
* @param {Object} object The object to modify.
|
16
|
* @param {Array|string} path The path of the property to set.
|
17
|
* @param {*} value The value to set.
|
18
|
* @param {Function} [customizer] The function to customize assigned values.
|
19
|
* @returns {Object} Returns `object`.
|
20
|
* @example
|
21
|
*
|
22
|
* var object = {};
|
23
|
*
|
24
|
* _.setWith(object, '[0][1]', 'a', Object);
|
25
|
* // => { '0': { '1': 'a' } }
|
26
|
*/
|
27
|
function setWith(object, path, value, customizer) {
|
28
|
customizer = typeof customizer == 'function' ? customizer : undefined;
|
29
|
return object == null ? object : baseSet(object, path, value, customizer);
|
30
|
}
|
31
|
|
32
|
module.exports = setWith;
|