MCPcopy Index your code
hub / github.com/angular/angular / serializeSegment

Function serializeSegment

packages/router/src/url_tree.ts:471–505  ·  view source on GitHub ↗
(segment: UrlSegmentGroup, root: boolean)

Source from the content-addressed store, hash-verified

469}
470
471function serializeSegment(segment: UrlSegmentGroup, root: boolean): string {
472 if (!segment.hasChildren()) {
473 return serializePaths(segment);
474 }
475
476 if (root) {
477 const primary = segment.children[PRIMARY_OUTLET]
478 ? serializeSegment(segment.children[PRIMARY_OUTLET], false)
479 : '';
480 const children: string[] = [];
481
482 Object.entries(segment.children).forEach(([k, v]) => {
483 if (k !== PRIMARY_OUTLET) {
484 children.push(`${k}:${serializeSegment(v, false)}`);
485 }
486 });
487
488 return children.length > 0 ? `${primary}(${children.join('//')})` : primary;
489 } else {
490 const children = mapChildrenIntoArray(segment, (v: UrlSegmentGroup, k: string) => {
491 if (k === PRIMARY_OUTLET) {
492 return [serializeSegment(segment.children[PRIMARY_OUTLET], false)];
493 }
494
495 return [`${k}:${serializeSegment(v, false)}`];
496 });
497
498 // use no parenthesis if the only child is a primary outlet route
499 if (Object.keys(segment.children).length === 1 && segment.children[PRIMARY_OUTLET] != null) {
500 return `${serializePaths(segment)}/${children[0]}`;
501 }
502
503 return `${serializePaths(segment)}/(${children.join('//')})`;
504 }
505}
506
507/**
508 * Encodes a URI string with the default encoding. This function will only ever be called from

Callers 1

serializeMethod · 0.85

Calls 8

serializePathsFunction · 0.85
mapChildrenIntoArrayFunction · 0.85
joinMethod · 0.65
keysMethod · 0.65
hasChildrenMethod · 0.45
forEachMethod · 0.45
entriesMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…