Skip to content

Instantly share code, notes, and snippets.

@marteinn
Forked from kares/jquery.parseparams.js
Created May 28, 2012 13:10
Show Gist options
  • Save marteinn/2819093 to your computer and use it in GitHub Desktop.
Save marteinn/2819093 to your computer and use it in GitHub Desktop.
jQuery.parseParams - parse query string paramaters into an object (jshint compatible)
/**
* $.parseParams - parse query string paramaters into an object.
*/
/*jshint regexp: false */
(function($) {
var re = /([^&=]+)=?([^&]*)/g;
var decodeRE = /\+/g; // Regex for replacing addition symbol with a space
var decode = function (str) { return decodeURIComponent( str.replace(decodeRE, " ") ); };
$.parseParams = function(query) {
var params = {}, e;
while ( (e = re.exec(query)) )
{
params[decode(e[1])] = decode(e[2]);
}
return params;
};
})(jQuery);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment