Skip to content

Instantly share code, notes, and snippets.

@DennisMartinez
Created June 23, 2016 20:11
Show Gist options
  • Select an option

  • Save DennisMartinez/34a17b3a6c5302582ac927577847b465 to your computer and use it in GitHub Desktop.

Select an option

Save DennisMartinez/34a17b3a6c5302582ac927577847b465 to your computer and use it in GitHub Desktop.
export function serialize(form, type = 'string') {
const elements = form.elements;
let data = new Map();
[...elements].forEach(element => {
if (!element.value.length) return;
data.set(element.name, element.value);
});
return [...data].join('&').replace(/,/g, '=');
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment