Current version of the joi package.
Whitelists a value
Alias for alternatives
Generates a type that will match one of the provided alternative schemas
Generates a schema object that matches any data type.
Generates a schema object that matches an array data type.
Validates a value against a schema and throws if validation fails.
the value to validate.
the schema object.
Validates a value against a schema, returns valid object, and throws if validation fails.
the value to validate.
the schema object.
Generates a schema object that matches a Buffer data type (as well as the strings which will be converted to Buffers).
Generates a schema object that matches a boolean data type (as well as the strings 'true', 'false', 'yes', and 'no'). Can also be called via bool().
Generates a schema object that matches a boolean data type (as well as the strings 'true', 'false', 'yes', and 'no'). Can also be called via bool().
Unsure, maybe alias for compile
?
Checks if the provided preferences are valid.
Throws an exception if the prefs object is invalid.
The method is provided to perform inputs validation for the any.validate()
and any.validateAsync()
methods.
Validation is not performed automatically for performance reasons. Instead, manually validate the preferences passed once and reuse.
Converts literal schema definition to joi schema object (or returns the same back if already a joi schema object).
Creates a custom validation schema.
Generates a schema object that matches a date type (as well as a JavaScript date string or number of milliseconds).
Creates a new Joi instance that will apply defaults onto newly created schemas through the use of the fn function that takes exactly one argument, the schema being created.
The function must always return a schema, even if untransformed.
Alias of required
.
Generates a dynamic expression using a template string.
Creates a new Joi instance customized with the extension(s) you provide included.
Marks a key as forbidden which will not allow any value except undefined. Used to explicitly forbid keys.
Generates a schema object that matches a function type.
Generates a schema object that matches a function type.
Creates a reference that when resolved, is used as an array of values to match against the rule.
Blacklists a value
Checks whether or not the provided argument is an instance of ValidationError
Checks whether or not the provided argument is an expression.
Checks whether or not the provided argument is a reference. It's especially useful if you want to post-process error messages.
Checks whether or not the provided argument is a joi schema.
Links to another schema node and reuses it for validation, typically for creative recursive schemas.
the reference to the linked schema node.
Cannot reference itself or its children as well as other links.
Links can be expressed in relative terms like value references (Joi.link('...')
),
in absolute terms from the schema run-time root (Joi.link('/a')
),
or using schema ids implicitly using object keys or explicitly using any.id()
(Joi.link('#a.b.c')
).
Generates a schema object that matches a number data type (as well as strings that can be converted to numbers).
Generates a schema object that matches an object data type (as well as JSON strings that have been parsed into objects).
Marks a key as optional which will allow undefined as values. Used to annotate the schema for readability as all keys are optional by default.
Unsure, maybe alias for preferences
?
Overrides the global validate() options for the current key and any sub-key.
Overrides the global validate() options for the current key and any sub-key.
Generates a reference to the value of the named key.
Marks a key as required which will not allow undefined as value. All keys are optional by default.
Generates a schema object that matches a string data type. Note that empty strings are not allowed by default and must be enabled with allow('').
Generates a schema object that matches any symbol.
Unsure, maybe leaked from @hapi/lab/coverage/initialize
Returns an object where each key is a plain joi schema type.
Useful for creating type shortcuts using deconstruction.
Note that the types are already formed and do not need to be called as functions (e.g. string
, not string()
).
Adds the provided values into the allowed whitelist and marks them as the only valid values allowed.
Converts the type into an alternatives type where the conditions are merged into the type definition where:
Generates a dynamic expression using a template string.
A special value used with
any.allow()
,any.invalid()
, andany.valid()
as the first value to reset any previously set values.