import type { ZodType, ZodTypeDef, ZodTypeAny, input, output } from 'zod/v3'; /** * Creates configured coercion functions for form value parsing. * * **Example:** * * ```tsx * import { configureCoercion } from '@conform-to/zod/v3/future'; * import { z } from 'zod'; * * const { coerceFormValue, coerceStructure } = configureCoercion({ * // Trim whitespace and treat whitespace-only as empty * stripEmptyString: (value) => { * const trimmed = value.trim(); * return trimmed === '' ? undefined : trimmed; * }, * type: { * // Strip commas from numbers like "1,000" before converting * number: (text) => Number(text.replace(/,/g, '')), * }, * }); * * const schema = z.object({ age: z.number(), name: z.string() }); * const validationSchema = coerceFormValue(schema); * const structuralSchema = coerceStructure(schema); * ``` */ export declare function configureCoercion(config?: { /** * Determines what string values are "empty" → undefined. * Receives a raw string and returns the string (possibly transformed) or * `undefined` to indicate empty. * * @default (value) => value === '' ? undefined : value * **Example: Treat whitespace-only strings as empty** * * ```ts * stripEmptyString: (value) => { * const trimmed = value.trim(); * return trimmed === '' ? undefined : trimmed; * } * ``` */ stripEmptyString?: (value: string) => string | undefined; /** * Type-specific string → typed value conversion functions. * Shared between validation and structural modes. The system handles * non-string passthrough and per-mode empty handling. * * Defaults: number via `Number()`, boolean checks `'on'`, date via * `new Date()`, bigint via `BigInt()` (not overridable here, use * `customize` instead). */ type?: { number?: (text: string) => number; boolean?: (text: string) => boolean; date?: (text: string) => Date; }; /** * Per-schema escape hatch. Return a coercion function to override * the default for a specific schema, or `null` to use the default. * The coercion function receives the raw form value (string, File, * array, etc.) and neither `stripEmptyString` nor `coerceString` * is applied automatically. */ customize?: (type: ZodTypeAny) => ((value: unknown) => unknown) | null; }): { /** * Enhances a schema to coerce form values and strip empty values before validation. * This configured helper uses the options passed to `configureCoercion`. * * Results are cached per schema, so this can be called inline. * * **Example:** * * ```tsx * const schema = coerceFormValue(z.object({ * age: z.number().optional(), * subscribe: z.boolean(), * })); * * schema.parse({ age: '', subscribe: 'on' }); * // { age: undefined, subscribe: true } * ``` */ coerceFormValue(type: Schema): ZodType, ZodTypeDef, input>; /** * Enhances a schema to coerce form values without running validation. * This configured helper is useful for reading current form values as typed data. * * It skips validation, defaults, transforms, and refinements, and does not strip * empty strings to `undefined`. * * For number, boolean, date, and bigint schemas, empty strings and other failed * string coercions still become fallback values: * * - `z.number()` -> `NaN` * - `z.boolean()` -> `false` * - `z.date()` -> `Invalid Date` * - `z.bigint()` -> `0n` * * Results are cached per schema, so this can be called inline. * * **Example:** * * ```tsx * const schema = coerceStructure(z.object({ * age: z.number().min(10), * })); * * schema.parse({ age: '3' }); * // { age: 3 } * ``` */ coerceStructure(type: Schema): ZodType, ZodTypeDef, input>; }; export declare const coerceFormValue: (type: Schema) => ZodType, ZodTypeDef, input>, coerceStructure: (type: Schema) => ZodType, ZodTypeDef, input>; //# sourceMappingURL=coercion.d.ts.map