Skip to content

Instantly share code, notes, and snippets.

@m1el
Created April 13, 2012 07:24
Show Gist options
  • Save m1el/2374794 to your computer and use it in GitHub Desktop.
Save m1el/2374794 to your computer and use it in GitHub Desktop.
function parseq(s) {
var o = {};
s.split("&").map(function (e) {
var
p = e.indexOf("="),
t = [e.substring(0, p), e.substring(p + 1)],
m = /^(\w+)\[['"](\w+)['"]\]$/.exec(t[0]);
if (m) {
o[m[1]] = o[m[1]] || {};
o[m[1]][m[2]] = t[1];
} else {
o[t[0]] = t[1];
}
});
return o;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment