| 220 | } |
| 221 | |
| 222 | function get(obj: any, path: string[]) { |
| 223 | for (let i = 0; i < path.length; ++i) { |
| 224 | let key = path[i] |
| 225 | |
| 226 | // The key does not exist so concatenate it with the next key. |
| 227 | // We use Object.hasOwn to avoid matching inherited prototype properties |
| 228 | // (e.g. "constructor", "toString") when traversing config objects. |
| 229 | if (obj === null || obj === undefined || typeof obj !== 'object' || !Object.hasOwn(obj, key)) { |
| 230 | if (path[i + 1] === undefined) { |
| 231 | return undefined |
| 232 | } |
| 233 | |
| 234 | path[i + 1] = `${key}-${path[i + 1]}` |
| 235 | continue |
| 236 | } |
| 237 | |
| 238 | obj = obj[key] |
| 239 | } |
| 240 | |
| 241 | return obj |
| 242 | } |
| 243 | |
| 244 | function set(obj: any, path: string[], value: any) { |
| 245 | for (let key of path.slice(0, -1)) { |