From e0bbadc2d2c50fce75ef1166d0991a5d04ef5e0a Mon Sep 17 00:00:00 2001 From: Phil Hughes Date: Thu, 7 Dec 2017 12:30:53 +0000 Subject: use exported methods instead of gl.utils --- app/assets/javascripts/lib/utils/url_utility.js | 23 ++++------------------- 1 file changed, 4 insertions(+), 19 deletions(-) (limited to 'app/assets/javascripts/lib/utils/url_utility.js') diff --git a/app/assets/javascripts/lib/utils/url_utility.js b/app/assets/javascripts/lib/utils/url_utility.js index f03848822a4..2129a7298d5 100644 --- a/app/assets/javascripts/lib/utils/url_utility.js +++ b/app/assets/javascripts/lib/utils/url_utility.js @@ -17,20 +17,17 @@ export function getParameterValues(sParam) { // @param {Object} params - url keys and value to merge // @param {String} url export function mergeUrlParams(params, url) { - let newUrl = Object.keys(params).reduce((accParam, paramName) => { + let newUrl = Object.keys(params).reduce((acc, paramName) => { const paramValue = params[paramName]; const pattern = new RegExp(`\\b(${paramName}=).*?(&|$)`); - let acc = accParam; if (paramValue === null) { - acc = acc.replace(pattern, ''); + return acc.replace(pattern, ''); } else if (url.search(pattern) !== -1) { - acc = acc.replace(pattern, `$1${paramValue}$2`); - } else { - acc = `${accParam}${accParam.indexOf('?') > 0 ? '&' : '?'}${paramName}=${paramValue}`; + return acc.replace(pattern, `$1${paramValue}$2`); } - return acc; + return `${acc}${acc.indexOf('?') > 0 ? '&' : '?'}${paramName}=${paramValue}`; }, decodeURIComponent(url)); // Remove a trailing ampersand @@ -86,15 +83,3 @@ export function refreshCurrentPage() { export function redirectTo(url) { return window.location.assign(url); } - -window.gl = window.gl || {}; -window.gl.utils = { - ...(window.gl.utils || {}), - mergeUrlParams, - getLocationHash, - getParameterValues, - redirectTo, - refreshCurrentPage, - removeParams, - visitUrl, -}; -- cgit v1.2.3