MCPcopy Create free account
hub / github.com/angular/angular / prefixedWith

Function prefixedWith

packages/router/src/create_url_tree.ts:478–510  ·  view source on GitHub ↗
(segmentGroup: UrlSegmentGroup, startIndex: number, commands: readonly any[])

Source from the content-addressed store, hash-verified

476}
477
478function prefixedWith(segmentGroup: UrlSegmentGroup, startIndex: number, commands: readonly any[]) {
479 let currentCommandIndex = 0;
480 let currentPathIndex = startIndex;
481
482 const noMatch = {match: false, pathIndex: 0, commandIndex: 0};
483 while (currentPathIndex < segmentGroup.segments.length) {
484 if (currentCommandIndex >= commands.length) return noMatch;
485 const path = segmentGroup.segments[currentPathIndex];
486 const command = commands[currentCommandIndex];
487 // Do not try to consume command as part of the prefixing if it has outlets because it can
488 // contain outlets other than the one being processed. Consuming the outlets command would
489 // result in other outlets being ignored.
490 if (isCommandWithOutlets(command)) {
491 break;
492 }
493 const curr = `${command}`;
494 const next =
495 currentCommandIndex < commands.length - 1 ? commands[currentCommandIndex + 1] : null;
496
497 if (currentPathIndex > 0 && curr === undefined) break;
498
499 if (curr && next && typeof next === 'object' && next.outlets === undefined) {
500 if (!compare(curr, next, path)) return noMatch;
501 currentCommandIndex += 2;
502 } else {
503 if (!compare(curr, {}, path)) return noMatch;
504 currentCommandIndex++;
505 }
506 currentPathIndex++;
507 }
508
509 return {match: true, pathIndex: currentPathIndex, commandIndex: currentCommandIndex};
510}
511
512function createNewSegmentGroup(
513 segmentGroup: UrlSegmentGroup,

Callers 1

updateSegmentGroupFunction · 0.85

Calls 2

isCommandWithOutletsFunction · 0.85
compareFunction · 0.70

Tested by

no test coverage detected