mirror of
https://github.com/lynchmarkHQ/lynchmark.com.git
synced 2026-10-14 16:17:53 +00:00
16 lines
445 B
JavaScript
16 lines
445 B
JavaScript
const validateJSON = async (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);
|
|
|
|
const errors = valid
|
|
? []
|
|
: validate.errors.map(
|
|
({ instancePath, message }) => `${instancePath || 'object'} ${message}`.trim()
|
|
);
|
|
|
|
return { valid, errors };
|
|
};
|
|
export default validateJSON; |