@conform-to/zod
Version:
Conform helpers for integrating with Zod
21 lines (17 loc) • 609 B
JavaScript
import { getZodConstraint } from './constraint.mjs';
/**
* Type guard to check if a value is a Zod v4 schema.
*/
function isSchema(schema) {
return typeof schema === 'object' && schema !== null && '~standard' in schema && typeof schema['~standard'] === 'object' && schema['~standard'] !== null && 'vendor' in schema['~standard'] && schema['~standard'].vendor === 'zod';
}
/**
* Extracts HTML validation attributes from a Zod v4 schema.
*/
function getConstraints(schema) {
if (!isSchema(schema)) {
return undefined;
}
return getZodConstraint(schema);
}
export { getConstraints, isSchema };