Created
January 31, 2017 07:19
-
-
Save railsstudent/bc702e73d1e5c0ee38a71d9d96a0de2e to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function stripUrlParams(url, paramsToStrip){ | |
let [urlPath, urlParams] = url.split('?'); | |
let paramKVMap = {}; | |
let urlDistinctParams = '' | |
if (urlParams) { | |
urlParams.split('&').forEach((e) => { | |
let [key, val] = e.split('='); | |
if (!paramsToStrip || !paramsToStrip.includes(key)) { | |
if (!paramKVMap[key]) { | |
paramKVMap[key] = val; | |
urlDistinctParams += `${key}=${val}&`; | |
} | |
} | |
}); | |
if (urlDistinctParams) { | |
urlDistinctParams = urlDistinctParams.substring(0, urlDistinctParams.length - 1); | |
} | |
} | |
return urlPath + (urlDistinctParams ? '?' + urlDistinctParams : ''); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment