main
Last change
on this file was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago |
F4 Finalna Verzija
|
-
Property mode
set to
100644
|
File size:
1.0 KB
|
Rev | Line | |
---|
[79a0317] | 1 | import type {CodeKeywordDefinition, ErrorObject, KeywordErrorDefinition} from "../../types"
|
---|
| 2 | import type {KeywordCxt} from "../../compile/validate"
|
---|
| 3 | import {_, str} from "../../compile/codegen"
|
---|
| 4 |
|
---|
| 5 | export type MultipleOfError = ErrorObject<
|
---|
| 6 | "multipleOf",
|
---|
| 7 | {multipleOf: number},
|
---|
| 8 | number | {$data: string}
|
---|
| 9 | >
|
---|
| 10 |
|
---|
| 11 | const error: KeywordErrorDefinition = {
|
---|
| 12 | message: ({schemaCode}) => str`must be multiple of ${schemaCode}`,
|
---|
| 13 | params: ({schemaCode}) => _`{multipleOf: ${schemaCode}}`,
|
---|
| 14 | }
|
---|
| 15 |
|
---|
| 16 | const def: CodeKeywordDefinition = {
|
---|
| 17 | keyword: "multipleOf",
|
---|
| 18 | type: "number",
|
---|
| 19 | schemaType: "number",
|
---|
| 20 | $data: true,
|
---|
| 21 | error,
|
---|
| 22 | code(cxt: KeywordCxt) {
|
---|
| 23 | const {gen, data, schemaCode, it} = cxt
|
---|
| 24 | // const bdt = bad$DataType(schemaCode, <string>def.schemaType, $data)
|
---|
| 25 | const prec = it.opts.multipleOfPrecision
|
---|
| 26 | const res = gen.let("res")
|
---|
| 27 | const invalid = prec
|
---|
| 28 | ? _`Math.abs(Math.round(${res}) - ${res}) > 1e-${prec}`
|
---|
| 29 | : _`${res} !== parseInt(${res})`
|
---|
| 30 | cxt.fail$data(_`(${schemaCode} === 0 || (${res} = ${data}/${schemaCode}, ${invalid}))`)
|
---|
| 31 | },
|
---|
| 32 | }
|
---|
| 33 |
|
---|
| 34 | export default def
|
---|
Note:
See
TracBrowser
for help on using the repository browser.