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