* 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. * @returns {Object} Re
(object, path, value, customizer)
| 511 | * @returns {Object} Returns `object`. |
| 512 | */ |
| 513 | function baseSet(object, path, value, customizer) { |
| 514 | if (!isObject(object)) { |
| 515 | return object; |
| 516 | } |
| 517 | path = isKey(path, object) ? [path] : castPath(path); |
| 518 | |
| 519 | var index = -1, |
| 520 | length = path.length, |
| 521 | lastIndex = length - 1, |
| 522 | nested = object; |
| 523 | |
| 524 | while (nested != null && ++index < length) { |
| 525 | var key = toKey(path[index]), |
| 526 | newValue = value; |
| 527 | |
| 528 | if (index != lastIndex) { |
| 529 | var objValue = nested[key]; |
| 530 | newValue = customizer ? customizer(objValue, key, nested) : undefined; |
| 531 | if (newValue === undefined) { |
| 532 | newValue = isObject(objValue) |
| 533 | ? objValue |
| 534 | : isIndex(path[index + 1]) |
| 535 | ? [] |
| 536 | : {}; |
| 537 | } |
| 538 | } |
| 539 | assignValue(nested, key, newValue); |
| 540 | nested = nested[key]; |
| 541 | } |
| 542 | return object; |
| 543 | } |
| 544 | |
| 545 | /** |
| 546 | * The base implementation of `_.toString` which doesn't convert nullish |