Last active
June 30, 2023 15:05
-
-
Save zplume/077121d2212c4e4280aedf138a3b495f to your computer and use it in GitHub Desktop.
This file contains 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
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