createFormData
The createFormData() function creates an extended FormData from nested values (objects and arrays) and keeps the original input in inputValues.
Supported values are:
string,File,boolean,number,null,undefinedDDate.TheDate,DDate.TheTime- nested objects and arrays of these values
Use TheFormData.toFlatEntries(...) when you need explicit flattened key/value pairs, and TheFormData.fromEntries(...) to rebuild nested objects after receiving form-data entries on the backend. During flattening, non-File values are converted to strings (null becomes "null").
Interactive example
Syntax
typescript
type EligibleFormDataValue =
| boolean
| number
| null
| string
| File
| undefined
| DDate.TheDate
| DDate.TheTime
| { [key: string]: EligibleFormDataValue }
| EligibleFormDataValue[];
class TheFormData<
GenericValues extends Record<string, EligibleFormDataValue>
> extends FormData {
readonly inputValues: GenericValues;
static toFlatEntries(
value: EligibleFormDataValue,
path?: string
): Iterable<[string, string | File]>;
static fromEntries(
iterable: Iterable<[string, unknown]>,
arrayMaxIndex: number
): object;
}
function createFormData<
GenericValues extends Record<string, EligibleFormDataValue>
>(
inputValues: GenericValues
): TheFormData<GenericValues>;Parameters
inputValues: Nested input object to convert intoFormData.iterable: Flat entries (typicallyFormData.entries()output) to reconstruct.arrayMaxIndex: Maximum accepted index when reconstructing arrays withfromEntries.value/path: Inputs used bytoFlatEntriesto recursively flatten data.
Return value
createFormData(...)returns aTheFormDatainstance.TheFormData.toFlatEntries(...)returns an iterable of flat[path, value]pairs.TheFormData.fromEntries(...)returns a reconstructed nested object.
toFlatEntries(...) serializes boolean, number, null, DDate.TheDate, and DDate.TheTime as strings.
See also
pipe- Compose transformations aroundcreateFormDatastringToBytes- String parsing helper often used with multipart metadata
