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

Function prefixedWith

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

Source from the content-addressed store, hash-verified

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

Callers 1

updateSegmentGroupFunction · 0.85

Calls 2

isCommandWithOutletsFunction · 0.85
compareFunction · 0.70

Tested by

no test coverage detected