* The base implementation of `_.set`. * * @private * @param {Object} object The object to modify. * @param {Array|string} path The path of the property to set. * @param {*} value The value to set. * @param {Function} [customizer] The function to customize path creation.
(object, path, value, customizer)
| 4023 | * @returns {Object} Returns `object`. |
| 4024 | */ |
| 4025 | function baseSet(object, path, value, customizer) { |
| 4026 | if (!isObject(object)) { |
| 4027 | return object; |
| 4028 | } |
| 4029 | path = castPath(path, object); |
| 4030 | |
| 4031 | var index = -1, |
| 4032 | length = path.length, |
| 4033 | lastIndex = length - 1, |
| 4034 | nested = object; |
| 4035 | |
| 4036 | while (nested != null && ++index < length) { |
| 4037 | var key = toKey(path[index]), |
| 4038 | newValue = value; |
| 4039 | |
| 4040 | if (key === '__proto__' || key === 'constructor' || key === 'prototype') { |
| 4041 | return object; |
| 4042 | } |
| 4043 | |
| 4044 | if (index != lastIndex) { |
| 4045 | var objValue = nested[key]; |
| 4046 | newValue = customizer ? customizer(objValue, key, nested) : undefined; |
| 4047 | if (newValue === undefined) { |
| 4048 | newValue = isObject(objValue) |
| 4049 | ? objValue |
| 4050 | : (isIndex(path[index + 1]) ? [] : {}); |
| 4051 | } |
| 4052 | } |
| 4053 | assignValue(nested, key, newValue); |
| 4054 | nested = nested[key]; |
| 4055 | } |
| 4056 | return object; |
| 4057 | } |
| 4058 | |
| 4059 | /** |
| 4060 | * The base implementation of `setData` without support for hot loop shorting. |
no test coverage detected