Created
August 14, 2019 06:46
-
-
Save AhnMo/704e9e1e385a7c122b0c559442cdb451 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
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