Function
getPath
(node: Node, parts: string[], create: boolean)
Source from the content-addressed store, hash-verified
| 264 | } |
| 265 | |
| 266 | function getPath(node: Node, parts: string[], create: boolean) { |
| 267 | if (parts.length === 0) return node |
| 268 | let current = node |
| 269 | for (const part of parts) { |
| 270 | let existing = current.children.find((x) => x.path.at(-1) === part) |
| 271 | if (!existing) { |
| 272 | if (!create) return |
| 273 | existing = { |
| 274 | path: current.path.concat(part), |
| 275 | children: [], |
| 276 | } |
| 277 | current.children.push(existing) |
| 278 | } |
| 279 | current = existing |
| 280 | } |
| 281 | return current |
| 282 | } |
| 283 | |
| 284 | const root: Node = { |
| 285 | path: [], |
Tested by
no test coverage detected