1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 export function getUrlParameter(search: string, name: string) {
6 const safeName = name.replace(/[[]/, '\\[').replace(/[\]]/, '\\]');
7 const regex = new RegExp('[\\?&]' + safeName + '=([^&#]*)');
8 const results = regex.exec(search);
9 return results === null ? '' : decodeURIComponent(results[1].replace(/\+/g, ' '));
12 export function normalizeURLPath(url: string) {
13 const u = new URL(url);
14 u.pathname = u.pathname.replace(/\/\//, '/');
15 if (u.pathname[u.pathname.length - 1] === '/') {
16 u.pathname = u.pathname.substring(0, u.pathname.length - 1);
21 export const customEncodeURI = (path: string) => {
23 return path.split('/').map(encodeURIComponent).join('/');
29 export const customDecodeURI = (path: string) => {
31 return path.split('%2F').map(decodeURIComponent).join('%2F');