mirror of
https://github.com/lynchmarkHQ/lynchmark.com.git
synced 2026-10-19 02:07:52 +00:00
Docs: Update benchmark results
This commit is contained in:
@@ -1,12 +1,24 @@
|
||||
let Ajv;
|
||||
async function validateJSON(json, schema) {
|
||||
if(!(json&&typeof json==='object')||!(schema===true||schema===false||(schema&&typeof schema==='object')))
|
||||
return{valid:false,errors:['Invalid input']};
|
||||
try{
|
||||
if(!Ajv){const m=await import('https://esm.sh/ajv@8');Ajv=m.default}
|
||||
const ajv=new Ajv({allErrors:true}),v=ajv.compile(schema);
|
||||
const valid=v(json);
|
||||
return{valid,errors:valid?[]:v.errors.map(e=>`${e.instancePath||'root'} ${e.message}`)};
|
||||
}catch(e){return{valid:false,errors:[e.message]}}
|
||||
}
|
||||
export default validateJSON;
|
||||
let a, c;
|
||||
|
||||
export const validateJSON = async (d, s) => {
|
||||
try {
|
||||
if (!a) {
|
||||
const { default: Ajv } = await import('https://esm.sh/ajv?bundle');
|
||||
a = new Ajv({ allErrors: true });
|
||||
c = new Map();
|
||||
}
|
||||
const k = JSON.stringify(s);
|
||||
if (!c.has(k)) c.set(k, a.compile(s));
|
||||
const v = c.get(k);
|
||||
const valid = v(d);
|
||||
return {
|
||||
valid,
|
||||
errors: valid ? [] : v.errors.map(e => `${e.instancePath || 'root'} ${e.message}`)
|
||||
};
|
||||
} catch (e) {
|
||||
return { valid: false, errors: [e.message] };
|
||||
}
|
||||
};
|
||||
export default validateJSON;
|
||||
// Generation time: 19.566s
|
||||
// Result: PASS
|
||||
Reference in New Issue
Block a user