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

Function stripTrailingSlash

packages/common/src/location/util.ts:40–48  ·  view source on GitHub ↗
(url: string)

Source from the content-addressed store, hash-verified

38 * @returns The URL string, modified if needed.
39 */
40export function stripTrailingSlash(url: string): string {
41 // Find the index of the first occurrence of `#`, `?`, or the end of the string.
42 // This marks the start of the query string, fragment, or the end of the URL path.
43 const pathEndIdx = url.search(/#|\?|$/);
44 // Check if the character before `pathEndIdx` is a trailing slash.
45 // If it is, remove the trailing slash and return the modified URL.
46 // Otherwise, return the URL as is.
47 return url[pathEndIdx - 1] === '/' ? url.slice(0, pathEndIdx - 1) + url.slice(pathEndIdx) : url;
48}
49
50/**
51 * Normalizes URL parameters by prepending with `?` if needed.

Callers 1

constructorMethod · 0.90

Calls 1

searchMethod · 0.45

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…