MCPcopy
hub / github.com/angular/angular / prefixedWith

Function prefixedWith

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

Source from the content-addressed store, hash-verified

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

Callers 1

updateSegmentGroupFunction · 0.85

Calls 2

isCommandWithOutletsFunction · 0.85
compareFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…