00001 var assignValue = require('./_assignValue'), 00002 castPath = require('./_castPath'), 00003 isIndex = require('./_isIndex'), 00004 isObject = require('./isObject'), 00005 toKey = require('./_toKey'); 00006 00017 function baseSet(object, path, value, customizer) { 00018 if (!isObject(object)) { 00019 return object; 00020 } 00021 path = castPath(path, object); 00022 00023 var index = -1, 00024 length = path.length, 00025 lastIndex = length - 1, 00026 nested = object; 00027 00028 while (nested != null && ++index < length) { 00029 var key = toKey(path[index]), 00030 newValue = value; 00031 00032 if (index != lastIndex) { 00033 var objValue = nested[key]; 00034 newValue = customizer ? customizer(objValue, key, nested) : undefined; 00035 if (newValue === undefined) { 00036 newValue = isObject(objValue) 00037 ? objValue 00038 : (isIndex(path[index + 1]) ? [] : {}); 00039 } 00040 } 00041 assignValue(nested, key, newValue); 00042 nested = nested[key]; 00043 } 00044 return object; 00045 } 00046 00047 module.exports = baseSet;