MCPcopy
hub / github.com/lodash/lodash / cloneByPath

Function cloneByPath

fp/_baseConvert.js:348–368  ·  view source on GitHub ↗

* Creates a clone of `object` by `path`. * * @private * @param {Object} object The object to clone. * @param {Array|string} path The path to clone by. * @returns {Object} Returns the cloned object.

(object, path)

Source from the content-addressed store, hash-verified

346 * @returns {Object} Returns the cloned object.
347 */
348 function cloneByPath(object, path) {
349 path = toPath(path);
350
351 var index = -1,
352 length = path.length,
353 lastIndex = length - 1,
354 result = clone(Object(object)),
355 nested = result;
356
357 while (nested != null && ++index < length) {
358 var key = path[index],
359 value = nested[key];
360
361 if (value != null &&
362 !(isFunction(value) || isError(value) || isWeakMap(value))) {
363 nested[key] = clone(index == lastIndex ? value : Object(value));
364 }
365 nested = nested[key];
366 }
367 return result;
368 }
369
370 /**
371 * Converts `lodash` to an immutable auto-curried iteratee-first data-last

Callers

nothing calls this directly

Calls 5

toPathFunction · 0.85
cloneFunction · 0.85
isFunctionFunction · 0.85
isErrorFunction · 0.85
isWeakMapFunction · 0.85

Tested by

no test coverage detected