Validator state starting points. These are validators that take an 'unknown' input.

See docs/VALIDATORS.md

Constructors

Methods

  • Creates a no-op validator. The value can be any type.

    Parameters

    • this: void

    Returns Validator<any, unknown>

  • Creates a validator that asserts that the input is an array.

    Parameters

    • this: void

    Returns ArraySchema<unknown[]>

  • Creates a validator that asserts that the input is an array and every element passes the given validator.

    Type Parameters

    • U

    Parameters

    Returns ArraySchema<U[]>

  • Creates a validator that asserts that the input is a boolean.

    Parameters

    • this: void

    Returns ValueSchema<boolean>

  • Creates a validator that asserts that the input is a function.

    Parameters

    • this: void

    Returns FunctionSchema<Fun>

  • Validates that the input is an instanceof the given prototype.

    Type Parameters

    • T

    Parameters

    • this: void
    • clazz: (new (...args: any[]) => T)
        • new (...args): T
        • Parameters

          • Rest...args: any[]

          Returns T

    Returns ValueSchema<T>

  • Creates a validator that asserts that the input is nullish or one of the given possible values.

    Type Parameters

    Parameters

    • this: void
    • Rest...possibleValues: U

    Returns ValueSchema<U[number]>

  • Creates a validator that asserts that the input is null.

    Parameters

    • this: void

    Returns Validator<null, unknown>

  • Creates a validator that asserts that the input is nullish.

    Parameters

    • this: void

    Returns Validator<undefined | null, unknown>

  • Creates a validator that asserts that the input is a number.

    Parameters

    • this: void

    Returns NumberSchema

  • Creates a validator that validates the input has properties that pass their respective validators.

    Type Parameters

    • U extends object

    Parameters

    • this: void
    • propertyValidators: {
          readonly [P in string | number | symbol]-?: Validator<U[P], unknown>
      }

    Returns ObjectSchema<U>

  • Returns a validator that asserts that the object's own enumerable properties has keys and values that match their respective validators.

    Prototype members are not included. Numeric keys are validated as strings. For example the object { [0]: 1 } will be passed to the key validator as '0'.

    To assume string keys, use recordValues

    Type Parameters

    • K extends string | symbol
    • V

    Parameters

    • this: void
    • keyValidator: Validator<K, unknown>

      Validates each key.

    • valueValidator: Validator<V, unknown>

      Validates each value.

    Returns RecordSchema<ReadonlyRecord<K, V>>

  • Returns a validator that asserts that the input object's own enumerable properties has string keys and values that match the given validator.

    Prototype members are not included.

    Type Parameters

    • V

    Parameters

    • this: void
    • valueValidator: Validator<V, unknown>

      Validates each value.

    Returns RecordSchema<Record<string, V>>

  • Returns a validator that asserts the input is a set with elements that match the given element validator.

    Type Parameters

    • U

    Parameters

    Returns SetSchema<Set<U>>

  • Creates a validator that asserts that the input is type 'string'.

    Parameters

    • this: void

    Returns StringSchema

  • Creates a validator that asserts that the input is type 'symbol'.

    Parameters

    • this: void

    Returns ValueSchema<symbol>

  • Creates a validator that asserts that the input array is a tuple whose elements match the given validators.

    Type Parameters

    • U extends readonly any[]

    Parameters

    • this: void
    • Rest...validators: {
          [Index in string | number | symbol]: Validator<U[Index<Index>], unknown>
      }

    Returns ArraySchema<{
        [Index in string | number | symbol]: U[Index<Index>]
    }>

  • Creates a validator that asserts that the input is strictly undefined.

    Parameters

    • this: void

    Returns Validator<undefined, unknown>