Function
setNestedValue
(
target: Record<string, any>,
path: Array<string>,
value: unknown,
)
Source from the content-addressed store, hash-verified
| 2241 | } |
| 2242 | |
| 2243 | function setNestedValue( |
| 2244 | target: Record<string, any>, |
| 2245 | path: Array<string>, |
| 2246 | value: unknown, |
| 2247 | ): void { |
| 2248 | if (path.length === 0) { |
| 2249 | return |
| 2250 | } |
| 2251 | |
| 2252 | let cursor = target |
| 2253 | for (let i = 0; i < path.length - 1; i++) { |
| 2254 | const segment = path[i]! |
| 2255 | const next = cursor[segment] |
| 2256 | if (next == null || typeof next !== `object`) { |
| 2257 | cursor[segment] = {} |
| 2258 | } |
| 2259 | cursor = cursor[segment] |
| 2260 | } |
| 2261 | cursor[path[path.length - 1]!] = value |
| 2262 | } |
| 2263 | |
| 2264 | function cloneForIncludesUpdate<T extends Record<string, any>>( |
| 2265 | target: T, |
Tested by
no test coverage detected