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.substr(0, u.pathname.length - 1);
21 export const escapeHashIfRequired = (name: string, defaultTransformation?: Function) =>
22 name.indexOf('#') > -1 ?
23 encodeURIComponent(name) :
24 defaultTransformation ?
25 defaultTransformation(name) :