Created
May 31, 2013 19:08
-
-
Save beatak/5687204 to your computer and use it in GitHub Desktop.
Works in progress and will make a github repo for this for realz. currently I copied from
http://stackoverflow.com/questions/901115/how-can-i-get-query-string-values things i wanted it be able to parse are: - array
-- ?a[]=1&a[]=2 // => { a: [1, 2]}
-- ?a[0]=1&a[1]=2 // => { a: [1, 2] } **maybe?** - different separator. i think ; (semi-colon) is…
This file contains hidden or 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
var parseQueryString = ( function () { | |
"use strict"; | |
return function (query) { | |
var match, | |
urlParams = {}, | |
pl = /\+/g, | |
search = /([^&=]+)=?([^&]*)/g, | |
decode = function (s) { return decodeURIComponent(s.replace(pl, " ")); }; | |
query = query || window.location.search; | |
if ( 0 === query.indexOf('?')) { | |
query = query.substring(1); | |
} | |
while (match = search.exec(query)) { | |
urlParams[decode(match[1])] = decode(match[2]); | |
} | |
return urlParams; | |
}; | |
})(); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Using regex for this is just wrong and will fail in some scenarios.
You'd better off using a tiny reusable module like:
https://github.com/sindresorhus/query-string