Skip to main content

StringSchema <T>

Type parameters

  • T = string

Hierarchy

Index

Methods

and

  • and(keys: string[], options?: Options): S
  • Map a list of field names that must be defined alongside this field.

camelCase

  • Require field value to be formatted in camel case (fooBar).

contains

  • Require field value to contain a provided string.

custom

  • Set a callback to run custom validation logic.

deprecate

  • deprecate(message: string): S
  • Set a message to log when this field is present.

kebabCase

  • Require field value to be formatted in kebab case (foo-bar).

lengthOf

  • lengthOf(size: number, options?: Options): S
  • Require field value to be of a specific string length.

lowerCase

  • Require field value to be all lower case.

match

  • match(pattern: RegExp, options?: Options): S
  • Require field value to match a defined regex pattern.

never

  • Mark that this field should never be used.

notEmpty

  • Require field value to not be an empty string.

notNullable

  • Disallow null values.

notUndefinable

  • Disallow undefined values. Will fallback to the default value.

nullable

  • Allow and return null values.

oneOf

  • Require field value to be one of the provided strings.


    Type parameters

    • I: string = string

only

  • Mark that this field can ONLY use a value that matches the default value.

optional

  • Require this field to NOT be explicitly defined.

or

  • or(keys: string[], options?: Options): S
  • Map a list of field names that must have at least 1 defined.

pascalCase

  • Require field value to be formatted in pascal case (FooBar).

required

  • Require this field to be explicitly defined.

schema

  • schema(): string
  • The type of schema.

snakeCase

  • Require field value to be formatted in snake case (foo_bar).

state

  • The internal state object. Contains useful metadata.

transform

  • Transform a value before it’s passed to the next criteria.

type

  • type(): string
  • The type of schema and it’s children (when applicable).

undefinable

  • Allow and return undefined values. Will NOT fallback to the default value.

upperCase

  • Require field value to be all upper case.

validate

  • Run all validation checks that have been enqueued and return a type casted value. If a value is undefined, inherit the default value, otherwise throw if required. If nullable and the value is null, return early.

when

  • Validate with another schema when a condition is met.

xor

  • xor(keys: string[], options?: Options): S
  • Map a list of field names that must not be defined alongside this field.