Skip to content

DylanPiercey/parse-form

Folders and files

NameName
Last commit message
Last commit date

Latest commit

ย 

History

30 Commits
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 
ย 

Repository files navigation

Utility convert a form to a javascript object in the way that a browser might. Supports files, and every type of native input.

Installation

npm install parse-form

Example

<form id="my-form">
  <input type="text" name="a[b][c]" value="hello world"/>
  <input type="file" name="myFyle" value=.../>
  <button type="submit">Submit</button>
</form>
import { parse } from "parse-form";

const form = document.getElementById("my-form");
parse(form);
/**
 * {
 *     body: { a: { b: { c: "hello world" } } },
 *     files: { myFile: [...] }
 * }
 */

API

parse(form: HTMLFormElement, shallow: boolean): { body: object, files: object }

  • Parses a form into a javascript object.
  • If shallow is true then nested keys such as a[b][c] won't be expanded.

Contributions

  • Use npm test to build and run tests.

Please feel free to create a PR!

About

๐Ÿ“ƒ Utility to easily parse forms in the browser.

Resources

Stars

Watchers

Forks

Packages

No packages published