UNPKG

@newdash/newdash

Version:

javascript/typescript utility library

40 lines (39 loc) 1.23 kB
"use strict"; var __importDefault = (this && this.__importDefault) || function (mod) { return (mod && mod.__esModule) ? mod : { "default": mod }; }; Object.defineProperty(exports, "__esModule", { value: true }); exports.update = void 0; const baseUpdate_1 = __importDefault(require("./.internal/baseUpdate")); /** * This method is like `set` except that it accepts `updater` to produce the * value to set. Use `updateWith` to customize `path` creation. The `updater` * is invoked with one argument: (value). * * **Note:** This method mutates `object`. * * @since 5.3.0 * @category Object * @param object The object to modify. * @param path The path of the property to set. * @param updater The function to produce the updated value. * @returns Returns `object`. * @example * * ```js * const object = { 'a': [{ 'b': { 'c': 3 } }] } * * update(object, 'a[0].b.c', n => n * n) * console.log(object.a[0].b.c) * // => 9 * * update(object, 'x[0].y.z', n => n ? n + 1 : 0) * console.log(object.x[0].y.z) * // => 0 * ``` */ function update(object, path, updater) { return object == null ? object : (0, baseUpdate_1.default)(object, path, updater); } exports.update = update; exports.default = update;