Options
All
  • Public
  • Public/Protected
  • All
Menu

Interface StringSchemaDecorator

Hierarchy

  • StringSchemaModifiers
  • TypedPropertyDecorator<string>
    • StringSchemaDecorator

Callable

  • StringSchemaDecorator<TClass, TKey>(target: TClass, propertyKey: TKey): void
  • Type parameters

    • TClass: MapAllowUnions<TClass, TKey, string>

    • TKey: string | symbol

    Parameters

    • target: TClass
    • propertyKey: TKey

    Returns void

Index

Methods

allow

  • Whitelists values. Note that this list of allowed values is in addition to any other permitted values. To create an exclusive list of values, use the Valid decorator.

    Parameters

    • value: any
    • Rest ...values: any[]

      Values to be whitelisted.

    Returns StringSchemaDecorator

alphanum

creditCard

custom

  • custom(schemaBuilder: (options: { joi: Root; schema: Schema }) => Schema): this
  • Allows specify schemas directly via Joi's schema api.

    Parameters

    • schemaBuilder: (options: { joi: Root; schema: Schema }) => Schema
        • (options: { joi: Root; schema: Schema }): Schema
        • Parameters

          • options: { joi: Root; schema: Schema }
            • joi: Root
            • schema: Schema

          Returns Schema

    Returns this

default

description

disallow

email

empty

  • Considers anything that matches the schema to be empty (undefined).

    Parameters

    • Optional schema: any

      any object or joi schema to match. An undefined schema unsets that rule.

    Returns StringSchemaDecorator

equal

  • Adds the provided values into the allowed whitelist for property and marks them as the only valid values allowed.

    Parameters

    • value: any
    • Rest ...values: any[]

      The only valid values this property can accept.

    Returns StringSchemaDecorator

  • Parameters

    • values: any[]

    Returns StringSchemaDecorator

error

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

exactLength

  • Specifies the exact string length required.

    Parameters

    • length: number

      The required string length.

    • Optional encoding: string

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

    Returns StringSchemaDecorator

example

forbidden

guid

  • Requires the string value to be a valid GUID.

    Parameters

    • Optional options: GuidOptions

      Optional. options.version specifies one or more acceptable versions. Can be an array or string with the following values: uuidv1, uuidv2, uuidv3, uuidv4, or uuidv5. If no version is specified then it is assumed to be a generic guid which will not validate the version or variant of the guid and just check for general structure format.

    Returns StringSchemaDecorator

hex

hostname

insensitive

  • Allows the value to match any value in the allowed list or disallowed list in a case insensitive comparison. e.g. @jf.string().valid('a').insensitive()

    Returns StringSchemaDecorator

invalid

ip

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

    Parameters

    • Optional options: IpOptions

      optional settings: version - One or more IP address versions to validate against. Valid values: ipv4, ipv6, ipvfuture cidr - Used to determine if a CIDR is allowed or not. Valid values: optional, required, forbidden

    Returns StringSchemaDecorator

isoDate

  • Requires the string value to be in valid ISO 8601 date format. If the validation convert option is on (enabled by default), the string will be forced to simplified extended ISO format (ISO 8601). Be aware that this operation uses javascript Date object, which does not support the full ISO format, so a few formats might not pass when using convert.

    Returns StringSchemaDecorator

label

lowercase

max

meta

min

not

note

only

optional

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

options

pattern

  • Defines a pattern rule.

    Parameters

    • pattern: RegExp

      A regular expression object the string value must match against.

    • Optional name: string

      Optional name for patterns (useful with multiple patterns).

    Returns StringSchemaDecorator

raw

regex

  • Defines a pattern rule.

    Parameters

    • pattern: RegExp

      A regular expression object the string value must match against.

    • Optional name: string

      Optional name for patterns (useful with multiple patterns).

    Returns StringSchemaDecorator

replace

  • Replace characters matching the given pattern with the specified replacement string.

    Parameters

    • pattern: 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 StringSchemaDecorator

required

strict

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

    Parameters

    • Optional isStrict: boolean

    Returns StringSchemaDecorator

strip

tag

token

trim

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

    Returns StringSchemaDecorator

unit

uppercase

uri

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

    Parameters

    • Optional options: UriOptions

      Optional settings: scheme - Specifies one or more acceptable Schemes, should only include the scheme name. Can be an Array or String (strings are automatically escaped for use in a Regular Expression). allowRelative - Allow relative URIs. Defaults to false. relativeOnly - Restrict only relative URIs. Defaults to false. allowQuerySquareBrackets - Allows unencoded square brackets inside the query string. This is NOT RFC 3986 compliant but query strings like abc[]=123&abc[]=456 are very common these days. Defaults to false. domain - Validate the domain component using the options specified in string.domain().

    Returns StringSchemaDecorator

valid

  • Adds the provided values into the allowed whitelist for property and marks them as the only valid values allowed.

    Parameters

    • value: any
    • Rest ...values: any[]

      The only valid values this property can accept.

    Returns StringSchemaDecorator

  • Parameters

    • values: any[]

    Returns StringSchemaDecorator

Generated using TypeDoc