Skip to content

Instantly share code, notes, and snippets.

@railsstudent
Created January 31, 2017 07:19
Show Gist options
  • Save railsstudent/bc702e73d1e5c0ee38a71d9d96a0de2e to your computer and use it in GitHub Desktop.
Save railsstudent/bc702e73d1e5c0ee38a71d9d96a0de2e to your computer and use it in GitHub Desktop.
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