source: trip-planner-front/node_modules/ajv/lib/vocabularies/validation/const.ts@ ceaed42

Last change on this file since ceaed42 was 6a3a178, checked in by Ema <ema_spirova@…>, 3 years ago

initial commit

  • Property mode set to 100644
File size: 863 bytes
Line 
1import type {CodeKeywordDefinition, ErrorObject, KeywordErrorDefinition} from "../../types"
2import type {KeywordCxt} from "../../compile/validate"
3import {_} from "../../compile/codegen"
4import {useFunc} from "../../compile/util"
5import equal from "../../runtime/equal"
6
7export type ConstError = ErrorObject<"const", {allowedValue: any}>
8
9const error: KeywordErrorDefinition = {
10 message: "must be equal to constant",
11 params: ({schemaCode}) => _`{allowedValue: ${schemaCode}}`,
12}
13
14const def: CodeKeywordDefinition = {
15 keyword: "const",
16 $data: true,
17 error,
18 code(cxt: KeywordCxt) {
19 const {gen, data, $data, schemaCode, schema} = cxt
20 if ($data || (schema && typeof schema == "object")) {
21 cxt.fail$data(_`!${useFunc(gen, equal)}(${data}, ${schemaCode})`)
22 } else {
23 cxt.fail(_`${schema} !== ${data}`)
24 }
25 },
26}
27
28export default def
Note: See TracBrowser for help on using the repository browser.