Skip to content

Instantly share code, notes, and snippets.

@kixxauth
Created April 1, 2010 12:17
Show Gist options
  • Save kixxauth/351733 to your computer and use it in GitHub Desktop.
Save kixxauth/351733 to your computer and use it in GitHub Desktop.
/**
* URL encode an object.
*/
exports.encode = function encode(data) {
var postData = [], value, property;
for(property in data) {
if (Object.prototype.hasOwnProperty.call(data, property)) {
value = ((typeof data[property] === "undefined") && "undefined" ||
(data[property] === null) && "null" ||
data[property].toString());
postData.push(encodeURIComponent(property).replace(/%20/g, "+") +
"=" + encodeURIComponent(value).replace(/%20/g, "+"));
}
}
return postData.join("&");
};
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment