Skip to content

Instantly share code, notes, and snippets.

@arafathusayn
Created May 31, 2022 12:31
Show Gist options
  • Save arafathusayn/13009d5bfc054cb1e257eeb298b6bb29 to your computer and use it in GitHub Desktop.
Save arafathusayn/13009d5bfc054cb1e257eeb298b6bb29 to your computer and use it in GitHub Desktop.
function rawFormDataToJSON(formDataStr) {
return JSON.stringify(formDataStr
.trim()
.split('\n')
.filter(l => !l.startsWith('//'))
.map(l => l.split(':'))
.reduce((a, c) => ({ ...a, [c[0]]: c[1] }), {}))
}
// USAGE:
rawFormDataToJSON(`
year:2022
user_name:Customer 03
//id:1
`)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment