1 var assignValue = require('./_assignValue'),
2 castPath = require('./_castPath'),
3 isIndex = require('./_isIndex'),
4 isObject = require('./isObject'),
5 toKey = require('./_toKey');
8 * The base implementation of `_.set`.
11 * @param {Object} object The object to modify.
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 if (!isObject(object)) {
21 path = castPath(path, object);
25 lastIndex = length - 1,
28 while (nested != null && ++index < length) {
29 var key = toKey(path[index]),
32 if (index != lastIndex) {
33 var objValue = nested[key];
34 newValue = customizer ? customizer(objValue, key, nested) : undefined;
35 if (newValue === undefined) {
36 newValue = isObject(objValue)
38 : (isIndex(path[index + 1]) ? [] : {});
41 assignValue(nested, key, newValue);
47 module.exports = baseSet;