source: trip-planner-front/node_modules/ajv/lib/vocabularies/jtd/error.ts

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

initial commit

  • Property mode set to 100644
File size: 746 bytes
Line 
1import type {KeywordErrorDefinition, KeywordErrorCxt, ErrorObject} from "../../types"
2import {_, Code} from "../../compile/codegen"
3
4export type _JTDTypeError<K extends string, T extends string, S> = ErrorObject<
5 K,
6 {type: T; nullable: boolean},
7 S
8>
9
10export function typeError(t: string): KeywordErrorDefinition {
11 return {
12 message: (cxt) => typeErrorMessage(cxt, t),
13 params: (cxt) => typeErrorParams(cxt, t),
14 }
15}
16
17export function typeErrorMessage({parentSchema}: KeywordErrorCxt, t: string): string {
18 return parentSchema?.nullable ? `must be ${t} or null` : `must be ${t}`
19}
20
21export function typeErrorParams({parentSchema}: KeywordErrorCxt, t: string): Code {
22 return _`{type: ${t}, nullable: ${!!parentSchema?.nullable}}`
23}
Note: See TracBrowser for help on using the repository browser.