mirror of
https://github.com/lynchmarkHQ/lynchmark.com.git
synced 2026-10-18 09:47:55 +00:00
10 lines
364 B
JavaScript
10 lines
364 B
JavaScript
const validateJSON = async (data, schema) => {
|
|
const { default: Ajv } = await import('https://esm.sh/ajv@8.17.1')
|
|
const validator = new Ajv({ allErrors: true }).compile(schema)
|
|
const valid = validator(data)
|
|
return {
|
|
valid,
|
|
errors: valid ? [] : validator.errors.map(e => `${e.instancePath || 'root'} ${e.message}`)
|
|
}
|
|
}
|
|
export default validateJSON; |