mirror of
https://github.com/lynchmarkHQ/lynchmark.com.git
synced 2026-10-15 08:37:53 +00:00
11 lines
343 B
JavaScript
11 lines
343 B
JavaScript
async function validateJSON(data, schema) {
|
|
const { default: Ajv } = await import('https://esm.sh/ajv@8');
|
|
const ajv = new Ajv({ allErrors: true });
|
|
const validate = ajv.compile(schema);
|
|
const valid = validate(data);
|
|
return {
|
|
valid,
|
|
errors: valid ? [] : validate.errors.map(e => e.message)
|
|
};
|
|
}
|
|
export default validateJSON; |