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

Function serializeSegment

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

Source from the content-addressed store, hash-verified

476}
477
478function serializeSegment(segment: UrlSegmentGroup, root: boolean): string {
479 if (!segment.hasChildren()) {
480 return serializePaths(segment);
481 }
482
483 if (root) {
484 const primary = segment.children[PRIMARY_OUTLET]
485 ? serializeSegment(segment.children[PRIMARY_OUTLET], false)
486 : '';
487 const children: string[] = [];
488
489 Object.entries(segment.children).forEach(([k, v]) => {
490 if (k !== PRIMARY_OUTLET) {
491 children.push(`${k}:${serializeSegment(v, false)}`);
492 }
493 });
494
495 return children.length > 0 ? `${primary}(${children.join('//')})` : primary;
496 } else {
497 const children = mapChildrenIntoArray(segment, (v: UrlSegmentGroup, k: string) => {
498 if (k === PRIMARY_OUTLET) {
499 return [serializeSegment(segment.children[PRIMARY_OUTLET], false)];
500 }
501
502 return [`${k}:${serializeSegment(v, false)}`];
503 });
504
505 // use no parenthesis if the only child is a primary outlet route
506 if (Object.keys(segment.children).length === 1 && segment.children[PRIMARY_OUTLET] != null) {
507 return `${serializePaths(segment)}/${children[0]}`;
508 }
509
510 return `${serializePaths(segment)}/(${children.join('//')})`;
511 }
512}
513
514/**
515 * 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