source: imaps-frontend/node_modules/ajv/lib/vocabularies/jtd/error.ts@ 79a0317

main
Last change on this file since 79a0317 was 79a0317, checked in by stefan toskovski <stefantoska84@…>, 3 days ago

F4 Finalna Verzija

  • 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.