Last active
September 29, 2017 12:17
-
-
Save hampusn/d10aa8008e469381124125063cf641a6 to your computer and use it in GitHub Desktop.
Get query parameters as literal 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
// Get query parameters as literal object. | |
var queryObject = (function (queryParams, k, v) { | |
return queryParams.reduce(function (params, p) { | |
if ((p = p.split('=')).length) { | |
k = p[0]; | |
v = p[0]; | |
params[k] = (typeof params[k] !== 'undefined') ? (Array.isArray(params[k]) ? params[k] : [params[k]]).concat(v) : v; | |
} | |
return params; | |
}, {}); | |
})(window.location.search.slice(1).split('&')); |
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
var queryObject=function(r,n,t){return r.reduce(function(r,c){return(c=c.split("=")).length&&(n=c[0],t=c[0],r[n]=void 0!==r[n]?(Array.isArray(r[n])?r[n]:[r[n]]).concat(t):t),r},{})}(window.location.search.slice(1).split("&")); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment