1 | "use strict";
|
2 | Object.defineProperty(exports, "__esModule", { value: true });
|
3 | const codegen_1 = require("../../compile/codegen");
|
4 | const error = {
|
5 | message: ({ schemaCode }) => (0, codegen_1.str) `must be multiple of ${schemaCode}`,
|
6 | params: ({ schemaCode }) => (0, codegen_1._) `{multipleOf: ${schemaCode}}`,
|
7 | };
|
8 | const 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 |
|
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 | };
|
25 | exports.default = def;
|
26 |
|
\ | No newline at end of file |