formdata-schema
v0.1.13
Published
Parse FormData with a simple schema
Downloads
42
Readme
formdata-schema
Parse your FormData
with a simple schema.
Installation
pnpm i formdata-schema
Usage
import { parse } from 'formdata-schema'
// data: FormData
const parsed = parse(data, {
first_name: 'nonempty',
last_name: 'nonempty',
height: 'number',
birthdate: 'date',
avatar: 'fileOptional',
note: 'text',
})
Type of parsed
:
Error | {
first_name: string // length > 0
last_name: string // length > 0
height: number
birthdate: Date
avatar: File | null
note: string
}