( root: Segment<State>, path: string, includeLast: boolean, )
| 47 | } |
| 48 | |
| 49 | export function getOrCreateSegment<State>( |
| 50 | root: Segment<State>, |
| 51 | path: string, |
| 52 | includeLast: boolean, |
| 53 | ): Segment<State> { |
| 54 | let current = root; |
| 55 | |
| 56 | const segments = patternToSegments(path, root.pattern, includeLast); |
| 57 | for (let i = 0; i < segments.length; i++) { |
| 58 | const seg = segments[i]; |
| 59 | if (seg === root.pattern) { |
| 60 | current = root; |
| 61 | } else { |
| 62 | let child = current.children.get(seg); |
| 63 | if (child === undefined) { |
| 64 | child = newSegment(seg, current); |
| 65 | current.children.set(seg, child); |
| 66 | } |
| 67 | |
| 68 | current = child; |
| 69 | } |
| 70 | } |
| 71 | |
| 72 | return current; |
| 73 | } |
| 74 | |
| 75 | export function segmentToMiddlewares<State>( |
| 76 | segment: Segment<State>, |
no test coverage detected