Skip to content

Instantly share code, notes, and snippets.

@JohnDMathis
Created October 20, 2016 04:47
Show Gist options
  • Save JohnDMathis/012dce3d4edd6d3ca2da57489a167a16 to your computer and use it in GitHub Desktop.
Save JohnDMathis/012dce3d4edd6d3ca2da57489a167a16 to your computer and use it in GitHub Desktop.
Convert a query string to object
// convert queryString to params
var params = {};
window.location.search.replace(
new RegExp("([^?=&]+)(=([^&]*))?", "g"),
function(a, key, b, val) {
var num = Number(val);
if( !_.isNaN(num) && _.isNumber(num) ){
val = num;
} else {
if(val==="true") {
val = true;
}
if(val==="false") {
val = false;
}
}
params[key] = val;
}
);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment