diff options
author | Phil Hughes <me@iamphill.com> | 2017-12-07 15:30:53 +0300 |
---|---|---|
committer | Phil Hughes <me@iamphill.com> | 2017-12-08 11:54:51 +0300 |
commit | e0bbadc2d2c50fce75ef1166d0991a5d04ef5e0a (patch) | |
tree | 08b7c296c4390bddcd5e0aee66a6b37f633c3d44 /app/assets/javascripts/lib/utils/url_utility.js | |
parent | 13df7a85cb6d934a5b0fdfc63810879647e9a28c (diff) |
use exported methods instead of gl.utils
Diffstat (limited to 'app/assets/javascripts/lib/utils/url_utility.js')
-rw-r--r-- | app/assets/javascripts/lib/utils/url_utility.js | 23 |
1 files changed, 4 insertions, 19 deletions
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, -}; |