Get a value from a nested object by dot-path.
(obj: Record<string, unknown>, path: string)
| 24 | |
| 25 | /** Get a value from a nested object by dot-path. */ |
| 26 | function getConfigAtPath(obj: Record<string, unknown>, path: string): unknown { |
| 27 | const parts = path.split("."); |
| 28 | let current: unknown = obj; |
| 29 | for (const part of parts) { |
| 30 | if (current === null || typeof current !== "object") return undefined; |
| 31 | current = (current as Record<string, unknown>)[part]; |
| 32 | } |
| 33 | return current; |
| 34 | } |
| 35 | |
| 36 | /** Set a value in a nested object by dot-path (mutates). */ |
| 37 | function setConfigAtPath(obj: Record<string, unknown>, path: string, value: unknown): boolean { |
no outgoing calls
no test coverage detected