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

Function getRelativeUrl

adev/shared-docs/utils/url.utils.ts:11–24  ·  view source on GitHub ↗
(
  absoluteUrl: string,
  result: 'relative' | 'pathname' | 'hash' = 'relative',
)

Source from the content-addressed store, hash-verified

9import {normalizePath} from './navigation.utils';
10
11export function getRelativeUrl(
12 absoluteUrl: string,
13 result: 'relative' | 'pathname' | 'hash' = 'relative',
14): string {
15 const url = new URL(normalizePath(absoluteUrl));
16
17 if (result === 'hash') {
18 return url.hash?.substring(1) ?? '';
19 }
20 if (result === 'pathname') {
21 return `${removeTrailingSlash(normalizePath(url.pathname))}`;
22 }
23 return `${removeTrailingSlash(normalizePath(url.pathname))}${url.hash ?? ''}`;
24}
25
26export const removeTrailingSlash = (url: string): string => {
27 if (url.endsWith('/')) {

Callers 2

Calls 2

normalizePathFunction · 0.90
removeTrailingSlashFunction · 0.70

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…