Skip to content

Instantly share code, notes, and snippets.

@unyo
Last active September 2, 2022 20:52
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save unyo/9baeb7909de80ff0923706ee2370aa6c to your computer and use it in GitHub Desktop.
Save unyo/9baeb7909de80ff0923706ee2370aa6c to your computer and use it in GitHub Desktop.
Curl to Form
// https://jsbin.com/datafudezo/1/edit?js,output
const input = ``; // paste your curl from chrome here
const action = input.match(/curl '([^']+)'/)[1];
const data = input.match(/data-raw '([^']+)'/)[1].split('&');
const inputs = data.map(function(keyval) {
const [key, val] = keyval.split('=');
return '<label for="'+key+'">'+key+'</label><br /><input type="text" id="'+key+'" name="'+key+'" value="'+val+'" /><br />';
});
document.write('<form action="'+action+'">'+inputs.join('\n')+'<input type="submit" /></form>');
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment