UNPKG

@canard/schema-form-ajv8-plugin

Version:

AJV 8.x validator plugin for @canard/schema-form providing JSON Schema validation with latest Draft 2020-12 and Draft 2019-09 support

22 lines (19 loc) 531 B
import { transformErrors } from './utils/transformErrors.mjs'; const createValidatorFactory = (ajv) => (jsonSchema) => { const validate = ajv.compile({ ...jsonSchema, $async: true, }); return async (data) => { try { await validate(data); return null; } catch (thrown) { if (Array.isArray(thrown?.errors)) return transformErrors(thrown.errors); throw thrown; } }; }; export { createValidatorFactory };