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