blob: 45eba2d8173df10548794b6dcf30a58824f304d0 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
|
/* This Source Code Form is subject to the terms of the Mozilla Public
* License, v. 2.0. If a copy of the MPL was not distributed with this
* file, You can obtain one at <http://mozilla.org/MPL/2.0/>. */
import { parse } from "../../utils/url";
/**
* Get the relative path of the url
* Does not include any query parameters or fragment parts
*
* @param string url
* @returns string path
*/
export function getRelativePath(url) {
const { pathname } = parse(url);
if (!pathname) {
return url;
}
const index = pathname.indexOf("/");
if (index !== -1) {
const path = pathname.slice(index + 1);
// If the path is empty this is likely the index file.
// e.g http://foo.com/
if (path == "") {
return "(index)";
}
return path;
}
return "";
}
|