1 var baseUpdate = require('./_baseUpdate'),
2 castFunction = require('./_castFunction');
5 * This method is like `_.set` except that accepts `updater` to produce the
6 * value to set. Use `_.updateWith` to customize `path` creation. The `updater`
7 * is invoked with one argument: (value).
9 * **Note:** This method mutates `object`.
15 * @param {Object} object The object to modify.
16 * @param {Array|string} path The path of the property to set.
17 * @param {Function} updater The function to produce the updated value.
18 * @returns {Object} Returns `object`.
21 * var object = { 'a': [{ 'b': { 'c': 3 } }] };
23 * _.update(object, 'a[0].b.c', function(n) { return n * n; });
24 * console.log(object.a[0].b.c);
27 * _.update(object, 'x[0].y.z', function(n) { return n ? n + 1 : 0; });
28 * console.log(object.x[0].y.z);
31 function update(object, path, updater) {
32 return object == null ? object : baseUpdate(object, path, castFunction(updater));
35 module.exports = update;