formDataToObject
function formDataToObject<T>(formData): T;Defined in: form-data-to-object-utils.ts:24
Convert a FormData into a plain object. A key that appears once becomes a
single value; a key that appears more than once (checkbox groups,
multi-selects) becomes an array, in submission order.
The type parameter is only a cast: nothing is validated or coerced, and
values stay string (or File). A field that can repeat comes back as a
single string when only one value was sent, so type it as
string | string[] or run the result through a schema.
Type Parameters
Section titled “Type Parameters”| Type Parameter | Default type |
|---|---|
T |
Record<string, unknown> |
Parameters
Section titled “Parameters”| Parameter | Type |
|---|---|
formData |
FormData |
Returns
Section titled “Returns”T
Example
Section titled “Example”import { formDataToObject } from "@xtandard/lib/web";
const form = new FormData();form.append("name", "Ada");form.append("tag", "math");form.append("tag", "code");
formDataToObject<{ name: string; tag: string | string[] }>(form);// { name: "Ada", tag: ["math", "code"] }