Options
All
  • Public
  • Public/Protected
  • All
Menu

Hierarchy

Index

Properties

$

0.0.46 provide

Starts a ruleset in order to apply multiple rule options. The set ends when rule(), keep(), message(), or warn() is called.

$_super

0.0.46 provide
$_super: Schema<any>

Parent schema object.

$_terms

0.0.46 provide
$_terms: Record<string, any>

Terms of current schema.

_flags

0.0.46 provide
_flags: Record<string, any>

Flags of current schema.

ruleset

0.0.46 provide
ruleset: StringSchema

Starts a ruleset in order to apply multiple rule options. The set ends when rule(), keep(), message(), or warn() is called.

Optional type

0.0.46 provide
type: string

Methods

$_addRule

0.0.46 provide

$_compile

0.0.46 provide

$_createError

0.0.46 provide

$_getFlag

0.0.46 provide
  • $_getFlag(name: string): any
  • Get value from given flag.

    Parameters

    • name: string

    Returns any

$_getRule

0.0.46 provide
  • Retrieve some rule configuration.

    Parameters

    • name: string

    Returns undefined | GetRuleOptions

$_mapLabels

0.0.46 provide
  • $_mapLabels(path: string | string[]): string
  • Parameters

    • path: string | string[]

    Returns string

$_match

0.0.46 provide
  • Returns true if validations runs fine on given value.

    Parameters

    Returns boolean

$_modify

0.0.46 provide

$_mutateRebuild

0.0.46 provide

$_mutateRegister

0.0.46 provide

$_property

0.0.46 provide
  • $_property(name: string): any
  • Get value from given property.

    Parameters

    • name: string

    Returns any

$_reach

0.0.46 provide
  • $_reach(path: string[]): Schema<any>
  • Get schema at given path.

    Parameters

    • path: string[]

    Returns Schema<any>

$_rootReferences

0.0.46 provide
  • $_rootReferences(): any
  • Get current schema root references.

    Returns any

$_setFlag

0.0.46 provide
  • Set flag to given value.

    Parameters

    Returns void

$_validate

0.0.46 provide

allow

0.0.46 provide
  • Whitelists a value

    Parameters

    • Rest ...values: any[]

    Returns StringSchema

alphanum

0.0.46 provide
  • Requires the string value to only contain a-z, A-Z, and 0-9.

    Returns StringSchema

alter

0.0.46 provide
  • Assign target alteration options to a schema that are applied when any.tailor() is called.

    Parameters

    • targets: Record<string, (schema: StringSchema) => Schema<any>>

      an object where each key is a target name, and each value is a function that takes an schema and returns an schema.

    Returns StringSchema

base64

0.0.46 provide
  • Requires the string value to be a valid base64 string; does not check the decoded value.

    Parameters

    Returns StringSchema

bind

0.0.46 provide
  • By default, some Joi methods to function properly need to rely on the Joi instance they are attached to because they use this internally. So Joi.string() works but if you extract the function from it and call string() it won't. bind() creates a new Joi instance where all the functions relying on this are bound to the Joi instance.

    Returns StringSchema

cache

0.0.46 provide
  • Adds caching to the schema which will attempt to cache the validation results (success and failures) of incoming inputs. If no cache is passed, a default cache is provisioned by using cache.provision() internally.

    Parameters

    Returns StringSchema

case

0.0.46 provide
  • Sets the required string case.

    Parameters

    • direction: "upper" | "lower"

    Returns StringSchema

cast

0.0.46 provide
  • cast(to: "string" | "number" | "map" | "set"): StringSchema
  • Casts the validated value to the specified type.

    Parameters

    • to: "string" | "number" | "map" | "set"

    Returns StringSchema

concat

0.0.46 provide
  • Returns a new type that is the result of adding the rules of one type to another.

    Parameters

    Returns StringSchema

creditCard

0.0.46 provide
  • Requires the number to be a credit card number (Using Lunh Algorithm).

    Returns StringSchema

custom

0.0.46 provide

dataUri

0.0.46 provide
  • Requires the string value to be a valid data URI string.

    Parameters

    Returns StringSchema

default

0.0.46 provide
  • Sets a default value if the original value is undefined where:

    Parameters

    • Optional value: null | string | number | boolean | object | any[] | Reference | ((parent: any, helpers: CustomHelpers<any>) => null | string | number | boolean | object | any[] | Reference)

      the default value. One of:

      • a literal value (string, number, object, etc.)
      • a references
      • a function which returns the default value using the signature function(parent, helpers) where:
        • parent - a clone of the object containing the value being validated. Note that since specifying a parent argument performs cloning, do not declare format arguments if you are not using them.
        • helpers - same as thsoe described in any.custom()

      When called without any value on an object schema type, a default value will be automatically generated based on the default values of the object keys.

      Note that if value is an object, any changes to the object after default() is called will change the reference and any future assignment.

    Returns StringSchema

describe

0.0.46 provide
  • Returns a plain object representing the schema's rules and properties

    Returns Description

description

0.0.46 provide

disallow

0.0.46 provide
  • Disallows values.

    Parameters

    • Rest ...values: any[]

    Returns StringSchema

domain

0.0.46 provide
  • Requires the string value to be a valid domain.

    Parameters

    Returns StringSchema

email

0.0.46 provide
  • Requires the string value to be a valid email address.

    Parameters

    Returns StringSchema

empty

0.0.46 provide

equal

0.0.46 provide
  • Adds the provided values into the allowed whitelist and marks them as the only valid values allowed.

    Parameters

    • Rest ...values: any[]

    Returns StringSchema

error

0.0.46 provide
  • Overrides the default joi error with a custom error if the rule fails where:

    Parameters

    • err: Error | ValidationErrorFunction

      can be: an instance of Error - the override error. a function(errors), taking an array of errors as argument, where it must either: return a string - substitutes the error message with this text return a single object or an Array of it, where: type - optional parameter providing the type of the error (eg. number.min). message - optional parameter if template is provided, containing the text of the error. template - optional parameter if message is provided, containing a template string, using the same format as usual joi language errors. context - optional parameter, to provide context to your error if you are using the template. return an Error - same as when you directly provide an Error, but you can customize the error message based on the errors.

      Note that if you provide an Error, it will be returned as-is, unmodified and undecorated with any of the normal joi error properties. If validation fails and another error is found before the error override, that error will be returned and the override will be ignored (unless the abortEarly option has been set to false).

    Returns StringSchema

example

0.0.46 provide
  • example(value: any, options?: { override: boolean }): StringSchema
  • Annotates the key with an example value, must be valid.

    Parameters

    • value: any
    • Optional options: { override: boolean }
      • override: boolean

    Returns StringSchema

exist

0.0.46 provide
  • Marks a key as required which will not allow undefined as value. All keys are optional by default.

    Returns StringSchema

external

0.0.46 provide
  • Adds an external validation rule.

    Note that external validation rules are only called after the all other validation rules for the entire schema (from the value root) are checked. This means that any changes made to the value by the external rules are not available to any other validation rules during the non-external validation phase. If schema validation failed, no external validation rules are called.

    Parameters

    Returns StringSchema

extract

0.0.46 provide
  • extract(path: string | string[]): Schema<any>
  • Returns a sub-schema based on a path of object keys or schema ids.

    Parameters

    • path: string | string[]

      a dot . separated path string or a pre-split array of path keys. The keys must match the sub-schema id or object key (if no id was explicitly set).

    Returns Schema<any>

failover

0.0.46 provide
  • Sets a failover value if the original value fails passing validation.

    Parameters

    • value: any

      the failover value. value supports references. value may be assigned a function which returns the default value.

      If value is specified as a function that accepts a single parameter, that parameter will be a context object that can be used to derive the resulting value. Note that if value is an object, any changes to the object after failover() is called will change the reference and any future assignment. Use a function when setting a dynamic value (e.g. the current time). Using a function with a single argument performs some internal cloning which has a performance impact. If you do not need access to the context, define the function without any arguments.

    Returns StringSchema

forbidden

0.0.46 provide
  • Marks a key as forbidden which will not allow any value except undefined. Used to explicitly forbid keys.

    Returns StringSchema

fork

0.0.46 provide
  • Returns a new schema where each of the path keys listed have been modified.

    Parameters

    • key: string | string[] | string[][]

      an array of key strings, a single key string, or an array of arrays of pre-split key strings.

    • adjuster: SchemaFunction

      a function which must return a modified schema.

    Returns StringSchema

guid

0.0.46 provide
  • Requires the string value to be a valid GUID.

    Parameters

    Returns StringSchema

hex

0.0.46 provide
  • Requires the string value to be a valid hexadecimal string.

    Parameters

    Returns StringSchema

hostname

0.0.46 provide
  • Requires the string value to be a valid hostname as per RFC1123.

    Returns StringSchema

id

0.0.46 provide
  • Sets a schema id for reaching into the schema via any.extract(). If no id is set, the schema id defaults to the object key it is associated with. If the schema is used in an array or alternatives type and no id is set, the schema in unreachable.

    Parameters

    • Optional name: string

    Returns StringSchema

insensitive

0.0.46 provide
  • Allows the value to match any whitelist of blacklist item in a case insensitive comparison.

    Returns StringSchema

invalid

0.0.46 provide
  • Disallows values.

    Parameters

    • Rest ...values: any[]

    Returns StringSchema

ip

0.0.46 provide
  • Requires the string value to be a valid ip address.

    Parameters

    Returns StringSchema

isoDate

0.0.46 provide
  • Requires the string value to be in valid ISO 8601 date format.

    Returns StringSchema

isoDuration

0.0.46 provide
  • Requires the string value to be in valid ISO 8601 duration format.

    Returns StringSchema

keep

0.0.46 provide
  • Same as rule({ keep: true }).

    Note that keep() will terminate the current ruleset and cannot be followed by another rule option. Use rule() to apply multiple rule options.

    Returns StringSchema

label

0.0.46 provide
  • Overrides the key name in error messages.

    Parameters

    • name: string

    Returns StringSchema

length

0.0.46 provide
  • Specifies the exact string length required

    Parameters

    • limit: number | Reference

      the required string length. It can also be a reference to another field.

    • Optional encoding: string

      if specified, the string length is calculated in bytes using the provided encoding.

    Returns StringSchema

lowercase

0.0.46 provide
  • Requires the string value to be all lowercase. If the validation convert option is on (enabled by default), the string will be forced to lowercase.

    Returns StringSchema

max

0.0.46 provide
  • Specifies the maximum number of string characters.

    Parameters

    • limit: number | Reference

      the maximum number of string characters allowed. It can also be a reference to another field.

    • Optional encoding: string

      if specified, the string length is calculated in bytes using the provided encoding.

    Returns StringSchema

message

0.0.46 provide
  • Same as rule({ message }).

    Note that message() will terminate the current ruleset and cannot be followed by another rule option. Use rule() to apply multiple rule options.

    Parameters

    • message: string

    Returns StringSchema

messages

0.0.46 provide
  • Same as any.prefs({ messages }). Note that while any.message() applies only to the last rule or ruleset, any.messages() applies to the entire schema.

    Parameters

    • messages: Record<string, string>

    Returns StringSchema

meta

0.0.46 provide
  • Attaches metadata to the key.

    Parameters

    • meta: object

    Returns StringSchema

min

0.0.46 provide
  • Specifies the minimum number string characters.

    Parameters

    • limit: number | Reference

      the minimum number of string characters required. It can also be a reference to another field.

    • Optional encoding: string

      if specified, the string length is calculated in bytes using the provided encoding.

    Returns StringSchema

normalize

0.0.46 provide
  • normalize(form?: "NFC" | "NFD" | "NFKC" | "NFKD"): StringSchema
  • Requires the string value to be in a unicode normalized form. If the validation convert option is on (enabled by default), the string will be normalized.

    Parameters

    • Optional form: "NFC" | "NFD" | "NFKC" | "NFKD"

    Returns StringSchema

not

0.0.46 provide
  • Disallows values.

    Parameters

    • Rest ...values: any[]

    Returns StringSchema

note

0.0.46 provide
  • Annotates the key

    Parameters

    • Rest ...notes: string[]

    Returns StringSchema

only

0.0.46 provide
  • Requires the validated value to match of the provided any.allow() values. It has not effect when called together with any.valid() since it already sets the requirements. When used with any.allow() it converts it to an any.valid().

    Returns StringSchema

optional

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

    Returns StringSchema

options

0.0.46 provide

pattern

0.0.46 provide
  • Defines a regular expression rule.

    Parameters

    • pattern: RegExp

      a regular expression object the string value must match against.

    • Optional options: string | StringRegexOptions

      optional, can be: Name for patterns (useful with multiple patterns). Defaults to 'required'. An optional configuration object with the following supported properties: name - optional pattern name. invert - optional boolean flag. Defaults to false behavior. If specified as true, the provided pattern will be disallowed instead of required.

    Returns StringSchema

preferences

0.0.46 provide

prefs

0.0.46 provide
  • Overrides the global validate() options for the current key and any sub-key.

    Parameters

    Returns StringSchema

presence

0.0.46 provide

raw

0.0.46 provide
  • Outputs the original untouched value instead of the casted value.

    Parameters

    • Optional enabled: boolean

    Returns StringSchema

regex

0.0.46 provide
  • Defines a regular expression rule.

    Parameters

    • pattern: RegExp

      a regular expression object the string value must match against.

    • Optional options: string | StringRegexOptions

      optional, can be: Name for patterns (useful with multiple patterns). Defaults to 'required'. An optional configuration object with the following supported properties: name - optional pattern name. invert - optional boolean flag. Defaults to false behavior. If specified as true, the provided pattern will be disallowed instead of required.

    Returns StringSchema

replace

0.0.46 provide
  • replace(pattern: string | RegExp, replacement: string): StringSchema
  • Replace characters matching the given pattern with the specified replacement string where:

    Parameters

    • pattern: string | RegExp

      a regular expression object to match against, or a string of which all occurrences will be replaced.

    • replacement: string

      the string that will replace the pattern.

    Returns StringSchema

required

0.0.46 provide
  • Marks a key as required which will not allow undefined as value. All keys are optional by default.

    Returns StringSchema

rule

0.0.46 provide
  • Applies a set of rule options to the current ruleset or last rule added.

    When applying rule options, the last rule (e.g. min()) is used unless there is an active ruleset defined (e.g. $.min().max()) in which case the options are applied to all the provided rules. Once rule() is called, the previous rules can no longer be modified and any active ruleset is terminated.

    Rule modifications can only be applied to supported rules. Most of the any methods do not support rule modifications because they are implemented using schema flags (e.g. required()) or special internal implementation (e.g. valid()). In those cases, use the any.messages() method to override the error codes for the errors you want to customize.

    Parameters

    Returns StringSchema

shared

0.0.46 provide
  • Registers a schema to be used by decendents of the current schema in named link references.

    Parameters

    Returns StringSchema

strict

0.0.46 provide
  • Sets the options.convert options to false which prevent type casting for the current key and any child keys.

    Parameters

    • Optional isStrict: boolean

    Returns StringSchema

strip

0.0.46 provide
  • Marks a key to be removed from a resulting object or array after validation. Used to sanitize output.

    Parameters

    • Optional enabled: boolean

    Returns StringSchema

tag

0.0.46 provide
  • Annotates the key

    Parameters

    • Rest ...tags: string[]

    Returns StringSchema

tailor

0.0.46 provide
  • tailor(targets: string | string[]): Schema<any>
  • Applies any assigned target alterations to a copy of the schema that were applied via any.alter().

    Parameters

    • targets: string | string[]

    Returns Schema<any>

token

0.0.46 provide
  • Requires the string value to only contain a-z, A-Z, 0-9, and underscore _.

    Returns StringSchema

trim

0.0.46 provide
  • Requires the string value to contain no whitespace before or after. If the validation convert option is on (enabled by default), the string will be trimmed.

    Parameters

    • Optional enabled: any

    Returns StringSchema

truncate

0.0.46 provide
  • Specifies whether the string.max() limit should be used as a truncation.

    Parameters

    • Optional enabled: boolean

    Returns StringSchema

unit

0.0.46 provide
  • Annotates the key with an unit name.

    Parameters

    • name: string

    Returns StringSchema

uppercase

0.0.46 provide
  • Requires the string value to be all uppercase. If the validation convert option is on (enabled by default), the string will be forced to uppercase.

    Returns StringSchema

uri

0.0.46 provide
  • Requires the string value to be a valid RFC 3986 URI.

    Parameters

    Returns StringSchema

uuid

0.0.46 provide
  • Requires the string value to be a valid GUID.

    Parameters

    Returns StringSchema

valid

0.0.46 provide
  • Adds the provided values into the allowed whitelist and marks them as the only valid values allowed.

    Parameters

    • Rest ...values: any[]

    Returns StringSchema

validate

0.0.46 provide

validateAsync

0.0.46 provide
  • Validates a value using the schema and options.

    Parameters

    Returns Promise<any>

warn

0.0.46 provide
  • Same as rule({ warn: true }). Note that warn() will terminate the current ruleset and cannot be followed by another rule option. Use rule() to apply multiple rule options.

    Returns StringSchema

warning

0.0.46 provide
  • Generates a warning. When calling any.validateAsync(), set the warning option to true to enable warnings. Warnings are reported separately from errors alongside the result value via the warning key (i.e. { value, warning }). Warning are always included when calling any.validate().

    Parameters

    Returns StringSchema

when

0.0.46 provide
  • Converts the type into an alternatives type where the conditions are merged into the type definition where:

    Parameters

    Returns StringSchema

  • Converts the type into an alternatives type where the conditions are merged into the type definition where:

    Parameters

    Returns StringSchema