MCPcopy Index your code
hub / github.com/wavetermdev/waveterm / getPath

Function getPath

frontend/util/ijson.ts:40–63  ·  view source on GitHub ↗
(obj: any, path: PathType)

Source from the content-addressed store, hash-verified

38}
39
40function getPath(obj: any, path: PathType): any {
41 let cur = obj;
42 for (const pathPart of path) {
43 if (cur == null) {
44 return null;
45 }
46 if (typeof pathPart === "string") {
47 if (isObject(cur)) {
48 cur = cur[pathPart];
49 } else {
50 return null;
51 }
52 } else if (typeof pathPart === "number") {
53 if (isArray(cur)) {
54 cur = cur[pathPart];
55 } else {
56 return null;
57 }
58 } else {
59 throw new Error("Invalid path part: " + pathPart);
60 }
61 }
62 return cur;
63}
64
65type SetPathOpts = {
66 force?: boolean;

Callers

nothing calls this directly

Calls 2

isObjectFunction · 0.70
isArrayFunction · 0.70

Tested by

no test coverage detected