mirror of
https://github.com/lynchmarkHQ/lynchmark.com.git
synced 2026-10-12 07:15:21 +00:00
15 lines
420 B
JavaScript
15 lines
420 B
JavaScript
async function validateJSON(data, schema) {
|
|
const { default: Ajv } = await import('https://esm.sh/ajv@8.12.0');
|
|
const ajv = new Ajv({ allErrors: true });
|
|
|
|
const validate = ajv.compile(schema);
|
|
const valid = validate(data);
|
|
|
|
return {
|
|
valid,
|
|
errors: valid ? [] : validate.errors.map(e => `${e.instancePath} ${e.message}`)
|
|
};
|
|
}
|
|
export default validateJSON;
|
|
// Generation time: 1.098s
|
|
// Result: PASS
|