1 | /**
|
2 | * lodash 4.0.0 (Custom Build) <https://lodash.com/>
|
3 | * Build: `lodash modularize exports="npm" -o ./`
|
4 | * Copyright 2012-2016 The Dojo Foundation <http://dojofoundation.org/>
|
5 | * Based on Underscore.js 1.8.3 <http://underscorejs.org/LICENSE>
|
6 | * Copyright 2009-2016 Jeremy Ashkenas, DocumentCloud and Investigative Reporters & Editors
|
7 | * Available under MIT license <https://lodash.com/license>
|
8 | */
|
9 | var baseSet = require('lodash._baseset');
|
10 |
|
11 | /**
|
12 | * Sets the value at `path` of `object`. If a portion of `path` doesn't exist
|
13 | * it's created. Arrays are created for missing index properties while objects
|
14 | * are created for all other missing properties. Use `_.setWith` to customize
|
15 | * `path` creation.
|
16 | *
|
17 | * @static
|
18 | * @memberOf _
|
19 | * @category Object
|
20 | * @param {Object} object The object to modify.
|
21 | * @param {Array|string} path The path of the property to set.
|
22 | * @param {*} value The value to set.
|
23 | * @returns {Object} Returns `object`.
|
24 | * @example
|
25 | *
|
26 | * var object = { 'a': [{ 'b': { 'c': 3 } }] };
|
27 | *
|
28 | * _.set(object, 'a[0].b.c', 4);
|
29 | * console.log(object.a[0].b.c);
|
30 | * // => 4
|
31 | *
|
32 | * _.set(object, 'x[0].y.z', 5);
|
33 | * console.log(object.x[0].y.z);
|
34 | * // => 5
|
35 | */
|
36 | function set(object, path, value) {
|
37 | return object == null ? object : baseSet(object, path, value);
|
38 | }
|
39 |
|
40 | module.exports = set;
|