mirror of
https://github.com/lynchmarkHQ/lynchmark.com.git
synced 2026-10-08 21:35:23 +00:00
9 lines
430 B
JavaScript
9 lines
430 B
JavaScript
export async function validateJSON(data, schema) {
|
|
const { default: Ajv } = await import('https://esm.sh/ajv@8?bundle');
|
|
const ajv = new Ajv({ allErrors: true, strict: false });
|
|
const validate = ajv.compile(schema);
|
|
const valid = validate(data);
|
|
const errors = valid ? [] : (validate.errors || []).map(e => `${e.instancePath || '/'} ${e.message || ''}`.trim());
|
|
return { valid, errors };
|
|
}
|
|
export default validateJSON; |