UNPKG

1.02 kBJavaScriptView Raw
1"use strict";
2Object.defineProperty(exports, "__esModule", { value: true });
3const codegen_1 = require("../../compile/codegen");
4const error = {
5 message: ({ schemaCode }) => (0, codegen_1.str) `must be multiple of ${schemaCode}`,
6 params: ({ schemaCode }) => (0, codegen_1._) `{multipleOf: ${schemaCode}}`,
7};
8const def = {
9 keyword: "multipleOf",
10 type: "number",
11 schemaType: "number",
12 $data: true,
13 error,
14 code(cxt) {
15 const { gen, data, schemaCode, it } = cxt;
16 // const bdt = bad$DataType(schemaCode, <string>def.schemaType, $data)
17 const prec = it.opts.multipleOfPrecision;
18 const res = gen.let("res");
19 const invalid = prec
20 ? (0, codegen_1._) `Math.abs(Math.round(${res}) - ${res}) > 1e-${prec}`
21 : (0, codegen_1._) `${res} !== parseInt(${res})`;
22 cxt.fail$data((0, codegen_1._) `(${schemaCode} === 0 || (${res} = ${data}/${schemaCode}, ${invalid}))`);
23 },
24};
25exports.default = def;
26//# sourceMappingURL=multipleOf.js.map
\No newline at end of file