Last active
February 25, 2022 15:22
-
-
Save westc/926e337baa74b931a156ab1f1e7f3b14 to your computer and use it in GitHub Desktop.
parseUrlQuery() Snippet - Parse URL query parameters.
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 parseUrlQuery(queryString) { | |
if (queryString.includes("=")) { | |
return JSON.stringify( | |
queryString.replace(/\+/g, '%20').split('&').reduce((dict, x) => { | |
var parts = x.split('=', 2); | |
dict[decodeURIComponent(parts[0])] = decodeURIComponent(parts[1]) || null; | |
return dict; | |
}, {}), | |
null, // No replacer | |
2 // indent with 2 spaces | |
); | |
} | |
return ""; | |
} |
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
{ | |
// Where the JS code lies | |
"files": ["parseUrlQuery.js"], | |
// Name of the function responsable for transforming the input into the output. | |
"transform": "parseUrlQuery", | |
// Input setup | |
"input": { "language": "text", "label": "Query String" }, | |
// Output setup | |
"output": { "language": "json", "label": "Resulting Parameters" }, | |
// Type of YourJS IO-App | |
"type": "split" | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Here is the corresponding IO App:
https://yourjs.com/gist-io/926e337baa74b931a156ab1f1e7f3b14