source: trip-planner-front/node_modules/ajv/dist/vocabularies/jtd/enum.js

Last change on this file 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 metadata_1 = require("./metadata");
5const nullable_1 = require("./nullable");
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 error,
14 code(cxt) {
15 metadata_1.checkMetadata(cxt);
16 const { gen, data, schema, schemaValue, parentSchema, it } = cxt;
17 if (schema.length === 0)
18 throw new Error("enum must have non-empty array");
19 if (schema.length !== new Set(schema).size)
20 throw new Error("enum items must be unique");
21 let valid;
22 const isString = codegen_1._ `typeof ${data} == "string"`;
23 if (schema.length >= it.opts.loopEnum) {
24 let cond;
25 [valid, cond] = nullable_1.checkNullable(cxt, isString);
26 gen.if(cond, loopEnum);
27 }
28 else {
29 /* istanbul ignore if */
30 if (!Array.isArray(schema))
31 throw new Error("ajv implementation error");
32 valid = codegen_1.and(isString, codegen_1.or(...schema.map((value) => codegen_1._ `${data} === ${value}`)));
33 if (parentSchema.nullable)
34 valid = codegen_1.or(codegen_1._ `${data} === null`, valid);
35 }
36 cxt.pass(valid);
37 function loopEnum() {
38 gen.forOf("v", schemaValue, (v) => gen.if(codegen_1._ `${valid} = ${data} === ${v}`, () => gen.break()));
39 }
40 },
41};
42exports.default = def;
43//# sourceMappingURL=enum.js.map
Note: See TracBrowser for help on using the repository browser.