Skip to content

Instantly share code, notes, and snippets.

@benjohnson
Created August 23, 2013 15:34
Show Gist options
  • Save benjohnson/6320676 to your computer and use it in GitHub Desktop.
Save benjohnson/6320676 to your computer and use it in GitHub Desktop.
Quick and dirty deparam function for dealing with querystrings created via traditional.
var deparam = function(paramString) {
var items = paramString.replace(/\+/g, ' ').split('&');
var returnObj = {};
_.each(items, function(params) {
var param = params.split('=');
returnObj[param[0]] = decodeURIComponent(param[1]);
var array = returnObj[param[0]].split(',');
if (array.length > 1) returnObj[param[0]] = array;
});
return returnObj;
}
console.log(deparam("currentPage=1&perPage=20&sort=lastmodified&sortOrder=desc&filterText=&filterAssignments=the-is-there-a-picture-assignment-even-longer-name%2Csb-assignment%2Cbook2&filterStatus=&filterType=poem&loading=true&_=1377264895003"));
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment