Skip to content

Instantly share code, notes, and snippets.

@AhnMo
Created August 14, 2019 06:46
Show Gist options
  • Save AhnMo/704e9e1e385a7c122b0c559442cdb451 to your computer and use it in GitHub Desktop.
Save AhnMo/704e9e1e385a7c122b0c559442cdb451 to your computer and use it in GitHub Desktop.
function encode_query_string(x) {
let output = [];
Object.keys(x).forEach(function(key) {
output.push(`${encodeURIComponent(key)}=${encodeURIComponent(x[key])}`);
});
return output.join('&');
}
function decode_query_string(x) {
let output = {};
x.split('&').forEach(function(item) {
let idx = item.indexOf('=');
output[decodeURIComponent(item.slice(0, idx))] = decodeURIComponent(item.slice(idx + 1));
});
return output;
}
encode_query_string(decode_query_string(window.location.search.slice(1)))
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment