MCPcopy Index your code
hub / github.com/json-editor/json-editor / code

Function code

docs/scripts/ajv-validator.js:361–399  ·  view source on GitHub ↗
(cxt)

Source from the content-addressed store, hash-verified

359 $data: true,
360 error,
361 code(cxt) {
362 const { gen, data, schemaCode, keyword, it } = cxt;
363 const { opts, self } = it;
364 if (!opts.validateFormats)
365 return;
366 const fCxt = new ajv_1.KeywordCxt(it, self.RULES.all.format.definition, "format");
367 if (fCxt.$data)
368 validate$DataFormat();
369 else
370 validateFormat();
371 function validate$DataFormat() {
372 const fmts = gen.scopeValue("formats", {
373 ref: self.formats,
374 code: opts.code.formats,
375 });
376 const fmt = gen.const("fmt", codegen_1._ `${fmts}[${fCxt.schemaCode}]`);
377 cxt.fail$data(codegen_1.or(codegen_1._ `typeof ${fmt} != "object"`, codegen_1._ `${fmt} instanceof RegExp`, codegen_1._ `typeof ${fmt}.compare != "function"`, compareCode(fmt)));
378 }
379 function validateFormat() {
380 const format = fCxt.schema;
381 const fmtDef = self.formats[format];
382 if (!fmtDef || fmtDef === true)
383 return;
384 if (typeof fmtDef != "object" ||
385 fmtDef instanceof RegExp ||
386 typeof fmtDef.compare != "function") {
387 throw new Error(`"${keyword}": format "${format}" does not define "compare" function`);
388 }
389 const fmt = gen.scopeValue("formats", {
390 key: format,
391 ref: fmtDef,
392 code: opts.code.formats ? codegen_1._ `${opts.code.formats}${codegen_1.getProperty(format)}` : undefined,
393 });
394 cxt.fail$data(compareCode(fmt));
395 }
396 function compareCode(fmt) {
397 return codegen_1._ `${fmt}.compare(${data}, ${schemaCode}) ${KWDs[keyword].fail} 0`;
398 }
399 },
400 dependencies: ["format"],
401 };
402 const formatLimitPlugin = (ajv) => {

Callers

nothing calls this directly

Calls 15

validate$DataFormatFunction · 0.85
validateFormatFunction · 0.85
validateAdditionalItemsFunction · 0.85
validateItemsFunction · 0.85
validateItemsWithCountFunction · 0.85
splitDependenciesFunction · 0.85
validatePropertyDepsFunction · 0.85
validateSchemaDepsFunction · 0.85
hasSchemaFunction · 0.85
validateIfFunction · 0.85
validateClauseFunction · 0.85

Tested by

no test coverage detected