MCPcopy Index your code
hub / github.com/triggerdotdev/jsonhero-web / pathToDescendant

Function pathToDescendant

app/utilities/jsonColumnView.ts:119–144  ·  view source on GitHub ↗
(
  ancestor: string,
  descendant: string
)

Source from the content-addressed store, hash-verified

117}
118
119export function pathToDescendant(
120 ancestor: string,
121 descendant: string
122): string | undefined {
123 const ancestorPath = new JSONHeroPath(ancestor);
124 const descendantPath = new JSONHeroPath(descendant);
125
126 const ancestorPathComponents = ancestorPath.components.map((component) =>
127 component.toString()
128 );
129 const descendantPathComponents = descendantPath.components.map((component) =>
130 component.toString()
131 );
132
133 const pathComponents = [];
134
135 for (let index = 0; index < descendantPathComponents.length; index++) {
136 const descendantPathComponent = descendantPathComponents[index];
137
138 if (ancestorPathComponents.length <= index) {
139 pathComponents.push(descendantPathComponent);
140 }
141 }
142
143 return pathComponents.join(".");
144}
145
146//Given the previous path and where the selection is, we calculate the new path
147//This allows us to keep the deepest item possible still visible whilst navigating around

Callers 1

ContainerInfoFunction · 0.90

Calls

no outgoing calls

Tested by

no test coverage detected