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