Skip to content

Instantly share code, notes, and snippets.

@pirey
Created December 2, 2018 16:26
Show Gist options
  • Save pirey/3b353db4a0cd92c5ac9a892ef47e1653 to your computer and use it in GitHub Desktop.
Save pirey/3b353db4a0cd92c5ac9a892ef47e1653 to your computer and use it in GitHub Desktop.
Collection of javascript helper functions
// convert FormData to Object
export const fd2obj = (fd) => Array.from(fd.entries()).reduce((acc, i) => Object.assign({}, acc, { [i[0]]: (acc[i[0]] || Array.isArray(acc[i[0]])) ? [].concat(acc[i[0]]).concat(i[1]) : i[1] }), {})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment