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