Docs: Update benchmark results

This commit is contained in:
github-actions[bot]
2025-11-07 22:07:45 +00:00
parent b5f81c6e8a
commit 1687dca49c
42 changed files with 784 additions and 847 deletions
@@ -1,32 +1,25 @@
let ajvPromise;
const compiledSchemas = new WeakMap();
const validateJSON = (() => {
let ajvPromise;
const validatorCache = new WeakMap();
return async (json, schema) => {
ajvPromise ||= import('https://cdn.jsdelivr.net/npm/ajv@8/dist/ajv2020.min.js')
.then(({ default: Ajv }) => new Ajv({ allErrors: true }));
const validateJSON = async (json, schema) => {
try {
ajvPromise ||= import('https://esm.sh/ajv@8').then(
({ default: Ajv }) => new Ajv({ allErrors: true })
);
const ajv = await ajvPromise;
let validate = compiledSchemas.get(schema);
let validate = validatorCache.get(schema);
if (!validate) {
validate = ajv.compile(schema);
compiledSchemas.set(schema, validate);
validatorCache.set(schema, validate);
}
const valid = validate(json);
const errors = valid
? []
: (validate.errors ?? []).map(({ instancePath, message }) =>
`${instancePath.substring(1) || 'root'}: ${message}`
);
const errors = valid ? [] : validate.errors.map(
({ instancePath, message }) => `${instancePath || 'object'} ${message}`
);
return { valid, errors };
} catch (error) {
return {
valid: false,
errors: [error.message || 'An unknown validation error occurred.'],
};
}
};
};
})();
export default validateJSON;