Skip to content

Instantly share code, notes, and snippets.

@tzmartin
Last active August 29, 2015 14:16
Show Gist options
  • Save tzmartin/097d17905802aabcb0fe to your computer and use it in GitHub Desktop.
Save tzmartin/097d17905802aabcb0fe to your computer and use it in GitHub Desktop.
Convert query parameters into JSON objects
var str = "myappscheme://foo=bar&hello=world"
var queryParamsToJSON = function(str) {
var result = {}, name;
str = str.split(/:\/\//);
str[1].substring(0, str[1].length).split(/\&|=/).forEach(function(item, idx){
idx%2 ? (result[name] = item) : (name = item);
});
return result;
};
var parsedArgs = queryParamsToJSON(str);
console.log(parsedArgs);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment