mirror of
https://github.com/lynchmarkHQ/lynchmark.com.git
synced 2026-10-17 17:27:53 +00:00
Docs: Update benchmark results
This commit is contained in:
@@ -1,11 +1,21 @@
|
||||
let ajvInstance;
|
||||
|
||||
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)
|
||||
};
|
||||
if (!ajvInstance) {
|
||||
const { default: Ajv } = await import('https://cdn.skypack.dev/ajv@8');
|
||||
ajvInstance = new Ajv({ allErrors: true });
|
||||
}
|
||||
const ajv = ajvInstance;
|
||||
try {
|
||||
const validate = ajv.compile(schema);
|
||||
const valid = validate(data);
|
||||
const errors = valid ? [] : ajv.errorsText(validate.errors, { separator: '\n' })
|
||||
.split('\n')
|
||||
.map(s => s.trim())
|
||||
.filter(Boolean);
|
||||
return { valid, errors };
|
||||
} catch (e) {
|
||||
return { valid: false, errors: [`Schema error: ${e.message}`] };
|
||||
}
|
||||
}
|
||||
export default validateJSON;
|
||||
Reference in New Issue
Block a user