JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 740
  • Score
    100M100P100Q92416F
  • License MIT

Utility to easily parse a form in the browser.

Package Exports

  • parse-form

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (parse-form) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme


Parse-Form
API Stability TypeScript Styled with prettier Build status Test Coverage NPM Version Downloads Browser Bundle Size

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!