import { GenericObject , Validator } from ".." ; import { objectFromPathEntries } from "../internal/flatten" ; const preprocessFormData = ( data ) : GenericObject => { if ( "entries" in data && typeof data . entries === "function" ) return objectFromPathEntries ( [ ... data . entries ( ) ] ) ; return objectFromPathEntries ( Object . entries ( data ) ) ; } ; /**
 * Used to create a validator for a form.
 * It provides built-in handling for unflattening nested objects and
 * extracting the values from FormData.
 */ export function createValidator < T > ( validator ) { return { validate : ( value ) => { const data = preprocessFormData ( value ) ; const result = validator . validate ( data ) ; if ( result . error ) { result . error . _submittedData = data as any ; } return result ; } , validateField : ( data , field ) => validator . validateField ( preprocessFormData ( data ) , field ) } ; }