1 var assignValue = require('./_assignValue'),
2 baseToPath = require('./_baseToPath'),
3 isIndex = require('./_isIndex'),
4 isKey = require('./_isKey'),
5 isObject = require('./isObject');
8 * The base implementation of `_.set`.
11 * @param {Object} object The object to query.
12 * @param {Array|string} path The path of the property to set.
13 * @param {*} value The value to set.
14 * @param {Function} [customizer] The function to customize path creation.
15 * @returns {Object} Returns `object`.
17 function baseSet(object, path, value, customizer) {
18 path = isKey(path, object) ? [path + ''] : baseToPath(path);
22 lastIndex = length - 1,
25 while (nested != null && ++index < length) {
26 var key = path[index];
27 if (isObject(nested)) {
29 if (index != lastIndex) {
30 var objValue = nested[key];
31 newValue = customizer ? customizer(objValue, key, nested) : undefined;
32 if (newValue === undefined) {
33 newValue = objValue == null ? (isIndex(path[index + 1]) ? [] : {}) : objValue;
36 assignValue(nested, key, newValue);
43 module.exports = baseSet;