Skip to content

Instantly share code, notes, and snippets.

@zplume
Last active June 30, 2023 15:05
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save zplume/077121d2212c4e4280aedf138a3b495f to your computer and use it in GitHub Desktop.
Save zplume/077121d2212c4e4280aedf138a3b495f to your computer and use it in GitHub Desktop.
const queryStrings = window.location.search.substring(1).split("&").reduce((output, item, index) => {
if(item === "")
return output;
const keyValue = item.split("=");
output[decodeURIComponent(keyValue[0])] = keyValue[1] !== undefined ?
decodeURIComponent(keyValue[1]) :
true; // return true for query strings with no value
return output;
}, {});
function getQueryString(key) {
const keyMatch = Object.keys(queryStrings).filter(item => item.match(new RegExp(`^${key}$`, "i")))[0];
return keyMatch !== undefined ? queryStrings[keyMatch] : undefined;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment