Created
August 23, 2013 15:34
-
-
Save benjohnson/6320676 to your computer and use it in GitHub Desktop.
Quick and dirty deparam function for dealing with querystrings created via traditional.
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 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