Function
getPath
(obj: any, path: PathType)
Source from the content-addressed store, hash-verified
| 38 | } |
| 39 | |
| 40 | function 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 | |
| 65 | type SetPathOpts = { |
| 66 | force?: boolean; |
Callers
nothing calls this directly
Tested by
no test coverage detected