Created
October 20, 2016 04:47
-
-
Save JohnDMathis/012dce3d4edd6d3ca2da57489a167a16 to your computer and use it in GitHub Desktop.
Convert a query string to object
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
// 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