( path: string, )
| 59 | * a given node by its location. |
| 60 | */ |
| 61 | export function decompressNodeLocation( |
| 62 | path: string, |
| 63 | ): [string | number, ...(number | NodeNavigationStep)[]] { |
| 64 | const matches = path.match(REF_EXTRACTOR_REGEXP)!; |
| 65 | const [_, refNodeId, refNodeName, rest] = matches; |
| 66 | // If a reference node is represented by an index, transform it to a number. |
| 67 | const ref = refNodeId ? parseInt(refNodeId, 10) : refNodeName; |
| 68 | const steps: (number | NodeNavigationStep)[] = []; |
| 69 | // Match all segments in a path. |
| 70 | for (const [_, step, count] of rest.matchAll(/(f|n)(\d*)/g)) { |
| 71 | const repeat = parseInt(count, 10) || 1; |
| 72 | steps.push(step as NodeNavigationStep, repeat); |
| 73 | } |
| 74 | return [ref, ...steps]; |
| 75 | } |
no test coverage detected
searching dependent graphs…