Validating
#
Sync vs AsyncAlmost all validation methods in @zuze/schema come in two flavors, async (default) and sync. Take a look at the api schemas api for more information.
#
Error MessagesError messages can be configured in several ways.
#
Global Error MessagesError messages are passed as the message
ValidationOption.
Default error messages are defined below.
Global error messages are simply defined as a map where the keys can be
${schemaType}.${validatorName}
${validatorName}
default
You can override global error messages like this:
#
Option to ValidatorAlmost all validators accept message as a parameter in the last argument.
This can be used to configure specific error messages for a given validator:
#
As functionsBoth global and validator specific error messages can be specified as functions or strings that can be interpolated.
By default label
and path
are provided as interpolation parameters. All over validators provide their own interpolation parameters specific to the validator (you can always override/extend these params using the params option to a validator).
#
As stringsWhen supplying error messages as strings values inside ${}
are interpolated.
Note: Do NOT put your message in backticks ``` if it is a string, this will treat it as a template literal which results in immediate interpolation rather than at validation time.