source: trip-planner-front/node_modules/ajv/dist/vocabularies/validation/enum.js@ 571e0df

Last change on this file since 571e0df was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 1.7 KB
Line 
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const codegen_1 = require("../../compile/codegen");
4const util_1 = require("../../compile/util");
5const equal_1 = require("../../runtime/equal");
6const error = {
7 message: "must be equal to one of the allowed values",
8 params: ({ schemaCode }) => codegen_1._ `{allowedValues: ${schemaCode}}`,
9};
10const def = {
11 keyword: "enum",
12 schemaType: "array",
13 $data: true,
14 error,
15 code(cxt) {
16 const { gen, data, $data, schema, schemaCode, it } = cxt;
17 if (!$data && schema.length === 0)
18 throw new Error("enum must have non-empty array");
19 const useLoop = schema.length >= it.opts.loopEnum;
20 const eql = util_1.useFunc(gen, equal_1.default);
21 let valid;
22 if (useLoop || $data) {
23 valid = gen.let("valid");
24 cxt.block$data(valid, loopEnum);
25 }
26 else {
27 /* istanbul ignore if */
28 if (!Array.isArray(schema))
29 throw new Error("ajv implementation error");
30 const vSchema = gen.const("vSchema", schemaCode);
31 valid = codegen_1.or(...schema.map((_x, i) => equalCode(vSchema, i)));
32 }
33 cxt.pass(valid);
34 function loopEnum() {
35 gen.assign(valid, false);
36 gen.forOf("v", schemaCode, (v) => gen.if(codegen_1._ `${eql}(${data}, ${v})`, () => gen.assign(valid, true).break()));
37 }
38 function equalCode(vSchema, i) {
39 const sch = schema[i];
40 return typeof sch === "object" && sch !== null
41 ? codegen_1._ `${eql}(${data}, ${vSchema}[${i}])`
42 : codegen_1._ `${data} === ${sch}`;
43 }
44 },
45};
46exports.default = def;
47//# sourceMappingURL=enum.js.map
Note: See TracBrowser for help on using the repository browser.