Skip to content

Instantly share code, notes, and snippets.

@edwilliams
Forked from ryoppy/getQueryParams.js
Last active April 20, 2016 15:04
Show Gist options
  • Select an option

  • Save edwilliams/395f58efcf5554c46933e35b5be85a45 to your computer and use it in GitHub Desktop.

Select an option

Save edwilliams/395f58efcf5554c46933e35b5be85a45 to your computer and use it in GitHub Desktop.
Parse query string. use Underscore.js.
/**
* Parse query string.
* ?a=b&c=d to {a: b, c: d}
* @param {String} (option) queryString
* @return {Object} query params
*/
_.getQueryParams = function(queryString) {
if (!queryString) { return false; }
return _.chain(queryString.split('&'))
.map(function(params) {
var p = params.split('=');
return [p[0], decodeURIComponent(p[1])];
})
.object()
.value();
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment