UNPKG

conform-to-valibot

Version:

Conform helpers for integrating with Valibot

148 lines (143 loc) 5.11 kB
import { Constraint, Intent, Submission } from '@conform-to/dom'; import { GenericSchema, GenericSchemaAsync, Config, BaseIssue, InferOutput } from 'valibot'; /** * @deprecated The official valibot support * [library](https://www.npmjs.com/package/@conform-to/valibot) * based on this library has been released. * * This project will be archived in the near future. * * To migrate, just install the official library * ( `npm install @conform-to/valibot` ) * and change the reference. * * @see https://www.npmjs.com/package/@conform-to/valibot */ declare function getValibotConstraint<T extends GenericSchema | GenericSchemaAsync>(schema: T): Record<string, Constraint>; /** * @deprecated The official valibot support * [library](https://www.npmjs.com/package/@conform-to/valibot) * based on this library has been released. * * This project will be archived in the near future. * * To migrate, just install the official library * ( `npm install @conform-to/valibot` ) * and change the reference. * * @see https://www.npmjs.com/package/@conform-to/valibot */ declare const conformValibotMessage: { VALIDATION_SKIPPED: string; VALIDATION_UNDEFINED: string; }; /** * @deprecated The official valibot support * [library](https://www.npmjs.com/package/@conform-to/valibot) * based on this library has been released. * * This project will be archived in the near future. * * To migrate, just install the official library * ( `npm install @conform-to/valibot` ) * and change the reference. * * @see https://www.npmjs.com/package/@conform-to/valibot */ declare function parseWithValibot<Schema extends GenericSchema>(payload: FormData | URLSearchParams, config: { schema: Schema | ((intent: Intent | null) => Schema); disableAutoCoercion?: boolean; info?: Pick<Config<BaseIssue<unknown>>, "abortEarly" | "abortPipeEarly" | "lang">; }): Submission<InferOutput<Schema>>; /** * @deprecated The official valibot support * [library](https://www.npmjs.com/package/@conform-to/valibot) * based on this library has been released. * * This project will be archived in the near future. * * To migrate, just install the official library * ( `npm install @conform-to/valibot` ) * and change the reference. * * @see https://www.npmjs.com/package/@conform-to/valibot */ declare function parseWithValibot<Schema extends GenericSchemaAsync>(payload: FormData | URLSearchParams, config: { schema: Schema | ((intent: Intent | null) => Schema); disableAutoCoercion?: boolean; info?: Pick<Config<BaseIssue<unknown>>, "abortEarly" | "abortPipeEarly" | "lang">; }): Promise<Submission<InferOutput<Schema>>>; /** * @deprecated The official valibot support * [library](https://www.npmjs.com/package/@conform-to/valibot) * based on this library has been released. * * This project will be archived in the near future. * * To migrate, just install the official library * ( `npm install @conform-to/valibot` ) * and change the reference. * * @see https://www.npmjs.com/package/@conform-to/valibot */ type CoercionFunction = (value: unknown) => unknown; type DefaultCoercionType = "string" | "file" | "number" | "boolean" | "date" | "bigint"; /** * @deprecated The official valibot support * [library](https://www.npmjs.com/package/@conform-to/valibot) * based on this library has been released. * * This project will be archived in the near future. * * To migrate, just install the official library * ( `npm install @conform-to/valibot` ) * and change the reference. * * @see https://www.npmjs.com/package/@conform-to/valibot * * A helper that enhance the valibot schema to strip empty value and coerce form value to the expected type with option to customize type coercion. * @example * * ```tsx * import { parseWithValibot, unstable_coerceFormValue as coerceFormValue } from '@conform-to/valibot'; * import { object, number, date, boolean } from 'valibot'; * * // To coerce the form value with default behaviour * const schema = coerceFormValue( * object({ * ref: number(), * date: date(), * amount: number(), * confirm: boolean(), * }) * ); * * // To coerce the form value with number type disabled * const schema = coerceFormValue( * object({ * ref: number(), * date: date(), * amount: number(), * confirm: boolean(), * }), * { * defaultCoercion: { * number: false, * }, * customize: (schema) => { * if (schema.type === 'string') { * return (value) => value.trim(); * } * return null; * }, * }, * ); * ``` */ declare function coerceFormValue<T extends GenericSchema | GenericSchemaAsync>(type: T, options?: { defaultCoercion?: { [key in DefaultCoercionType]?: CoercionFunction | boolean; }; customize?: (type: GenericSchema | GenericSchemaAsync) => CoercionFunction | null; }): T extends GenericSchema ? GenericSchema : GenericSchemaAsync; export { type CoercionFunction, conformValibotMessage, getValibotConstraint, parseWithValibot, coerceFormValue as unstable_coerceFormValue };