MCPcopy Index your code
hub / github.com/react/react / renamePathInObject

Function renamePathInObject

packages/react-devtools-shared/src/utils.js:649–668  ·  view source on GitHub ↗
(
  object: Object,
  oldPath: Array<string | number>,
  newPath: Array<string | number>,
)

Source from the content-addressed store, hash-verified

647}
648
649export function renamePathInObject(
650 object: Object,
651 oldPath: Array<string | number>,
652 newPath: Array<string | number>,
653) {
654 const length = oldPath.length;
655 if (object != null) {
656 const parent = getInObject(object, oldPath.slice(0, length - 1));
657 if (parent) {
658 const lastOld = oldPath[length - 1];
659 const lastNew = newPath[length - 1];
660 parent[lastNew] = parent[lastOld];
661 if (isArray(parent)) {
662 parent.splice(((lastOld: any): number), 1);
663 } else {
664 delete parent[lastOld];
665 }
666 }
667 }
668}
669
670export function setInObject(
671 object: Object,

Callers 2

renamePathFunction · 0.90
renamePathFunction · 0.90

Calls 2

getInObjectFunction · 0.85
isArrayFunction · 0.85

Tested by

no test coverage detected