-
-
Save lsmith/89293 to your computer and use it in GitHub Desktop.
This file contains hidden or 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
YUI('lang', function (Y) { | |
YAP.toQueryString = function (obj, name) { | |
switch (Y.Lang.type(obj)) { | |
case 'undefined': | |
case 'null': | |
return name ? encodeURIComponent(name) + '=' : ''; | |
case 'boolean': obj = +obj; // intentional fallthrough | |
case 'number': | |
case 'string': | |
return encodeURIComponent(name) + '=' + encodeURIComponent(obj); | |
case 'array': | |
var s = [], i, l; | |
name = name + '[]'; | |
for (i = 0, l = obj.length; i < l; ++i) { | |
s[i] = arguments.callee(obj[i], name); | |
} | |
return s.join('&'); | |
case 'object': // all other types are assumed to be objects | |
var s = [], | |
begin = name ? name + '[' : '', | |
end = name ? ']' : '', | |
key; | |
for (key in obj) { | |
if (obj.hasOwnProperty(key) && p.slice(-3) !== '___') { | |
s.push(arguments.callee(obj[key], begin + key + end)); | |
} | |
} | |
return s.join("&"); | |
default: return ''; // functions, regex, errors not acceptable | |
}; | |
}); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment