mirror of
https://github.com/angular/angular.git
synced 2026-09-14 13:54:52 +08:00
6ff53b7437
This is now the default value, so safe to remove PR Close #58914
28 lines
837 B
TypeScript
28 lines
837 B
TypeScript
/*!
|
|
* @license
|
|
* Copyright Google LLC All Rights Reserved.
|
|
*
|
|
* Use of this source code is governed by an MIT-style license that can be
|
|
* found in the LICENSE file at https://angular.dev/license
|
|
*/
|
|
|
|
import {Pipe, PipeTransform} from '@angular/core';
|
|
import {normalizePath, removeTrailingSlash} from '../utils/index';
|
|
|
|
@Pipe({
|
|
name: 'relativeLink',
|
|
})
|
|
export class RelativeLink implements PipeTransform {
|
|
transform(absoluteUrl: string, result: 'relative' | 'pathname' | 'hash' = 'relative'): string {
|
|
const url = new URL(normalizePath(absoluteUrl));
|
|
|
|
if (result === 'hash') {
|
|
return url.hash?.substring(1) ?? '';
|
|
}
|
|
if (result === 'pathname') {
|
|
return `${removeTrailingSlash(normalizePath(url.pathname))}`;
|
|
}
|
|
return `${removeTrailingSlash(normalizePath(url.pathname))}${url.hash ?? ''}`;
|
|
}
|
|
}
|