MCPcopy Create free account
hub / github.com/Lemoncode/fonk / baseSet

Function baseSet

src/helpers/set.js:513–543  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

511 * @returns {Object} Returns `object`.
512 */
513function 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

Callers 1

setFunction · 0.85

Calls 6

isIndexFunction · 0.85
assignValueFunction · 0.85
isObjectFunction · 0.70
isKeyFunction · 0.70
castPathFunction · 0.70
toKeyFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…