Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save andrew-ma/8bde01013d9a084a9f3637523a6b217e to your computer and use it in GitHub Desktop.
Save andrew-ma/8bde01013d9a084a9f3637523a6b217e to your computer and use it in GitHub Desktop.
JS object to application/x-www-form-urlencoded content-type
/**
* @param {Object} object
* @return {string}
*/
export function toFormUrlEncoded(object) {
return Object.entries(object)
.map(([key, value]) => `${encodeURIComponent(key)}=${encodeURIComponent(value)}`)
.join('&');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment