.gitignore added
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / table / node_modules / ajv / dist / vocabularies / jtd / type.js
1 "use strict";
2 Object.defineProperty(exports, "__esModule", { value: true });
3 exports.intRange = void 0;
4 const codegen_1 = require("../../compile/codegen");
5 const timestamp_1 = require("../../runtime/timestamp");
6 const util_1 = require("../../compile/util");
7 const metadata_1 = require("./metadata");
8 const error_1 = require("./error");
9 exports.intRange = {
10     int8: [-128, 127, 3],
11     uint8: [0, 255, 3],
12     int16: [-32768, 32767, 5],
13     uint16: [0, 65535, 5],
14     int32: [-2147483648, 2147483647, 10],
15     uint32: [0, 4294967295, 10],
16 };
17 const error = {
18     message: (cxt) => error_1.typeErrorMessage(cxt, cxt.schema),
19     params: (cxt) => error_1.typeErrorParams(cxt, cxt.schema),
20 };
21 const def = {
22     keyword: "type",
23     schemaType: "string",
24     error,
25     code(cxt) {
26         metadata_1.checkMetadata(cxt);
27         const { gen, data, schema, parentSchema } = cxt;
28         let cond;
29         switch (schema) {
30             case "boolean":
31             case "string":
32                 cond = codegen_1._ `typeof ${data} == ${schema}`;
33                 break;
34             case "timestamp": {
35                 const vts = util_1.useFunc(gen, timestamp_1.default);
36                 cond = codegen_1._ `${data} instanceof Date || (typeof ${data} == "string" && ${vts}(${data}))`;
37                 break;
38             }
39             case "float32":
40             case "float64":
41                 cond = codegen_1._ `typeof ${data} == "number"`;
42                 break;
43             default: {
44                 const [min, max] = exports.intRange[schema];
45                 cond = codegen_1._ `typeof ${data} == "number" && isFinite(${data}) && ${data} >= ${min} && ${data} <= ${max} && !(${data} % 1)`;
46             }
47         }
48         cxt.pass(parentSchema.nullable ? codegen_1.or(codegen_1._ `${data} === null`, cond) : cond);
49     },
50 };
51 exports.default = def;
52 //# sourceMappingURL=type.js.map