@cowwoc/requirements - v4.0.12
    Preparing search index...

    Interface JavascriptRequireThat

    Creates validators for the Javascript API that throw errors immediately on validation failure.

    interface JavascriptRequireThat {
        requireThat<T>(value: T, name: string): UnknownValidator<T>;
        requireThatArray<T extends undefined | null | E[], E>(
            value: T,
            name: string,
        ): ArrayValidator<T, E>;
        requireThatBoolean<T extends undefined | null | boolean>(
            value: T,
            name: string,
        ): BooleanValidator<T>;
        requireThatMap<T extends undefined | null | Map<K, V>, K, V>(
            value: T,
            name: string,
        ): MapValidator<T, K, V>;
        requireThatNumber<T extends undefined | null | number>(
            value: T,
            name: string,
        ): NumberValidator<T>;
        requireThatSet<T extends undefined | null | Set<E>, E>(
            value: T,
            name: string,
        ): SetValidator<T, E>;
        requireThatString<T extends undefined | null | string>(
            value: T,
            name: string,
        ): StringValidator<T>;
    }

    Implemented by

    Index

    Methods

    • Validates the state of an unknown value or a value that does not have a specialized validator.

      The returned validator throws an error immediately if a validation fails.

      Type Parameters

      • T

        the type of the value

      Parameters

      • value: T

        the value

      • name: string

        the name of the value

      Returns UnknownValidator<T>

      a validator for the value

      TypeError if name is undefined or null

      RangeError if name contains whitespace or is empty

    • Validates the state of an array.

      The returned validator throws an error immediately if a validation fails.

      Type Parameters

      • T extends undefined | null | E[]

        the type of the value

      • E

        the type of elements in the collection

      Parameters

      • value: T

        the value

      • name: string

        the name of the value

      Returns ArrayValidator<T, E>

      a validator for the value

      TypeError if name is undefined or null

      RangeError if name contains whitespace or is empty

    • Validates the state of a boolean.

      The returned validator throws an error immediately if a validation fails.

      Type Parameters

      • T extends undefined | null | boolean

        the type of the value

      Parameters

      • value: T

        the value

      • name: string

        the name of the value

      Returns BooleanValidator<T>

      a validator for the value

      TypeError if name is undefined or null

      RangeError if name contains whitespace or is empty

    • Validates the state of a Map.

      The returned validator throws an error immediately if a validation fails.

      Type Parameters

      • T extends undefined | null | Map<K, V>

        the type of the value

      • K

        the type of keys in the map

      • V

        the type of values in the map

      Parameters

      • value: T

        the value

      • name: string

        the name of the value

      Returns MapValidator<T, K, V>

      a validator for the value

      TypeError if name is undefined or null

      RangeError if name contains whitespace or is empty

    • Validates the state of a number.

      The returned validator throws an error immediately if a validation fails.

      Type Parameters

      • T extends undefined | null | number

        the type of the value

      Parameters

      • value: T

        the value

      • name: string

        the name of the value

      Returns NumberValidator<T>

      a validator for the value

      TypeError if name is undefined or null

      RangeError if name contains whitespace or is empty

    • Validates the state of a Set.

      The returned validator throws an error immediately if a validation fails.

      Type Parameters

      • T extends undefined | null | Set<E>

        the type of the value

      • E

        the type of elements in the set

      Parameters

      • value: T

        the value

      • name: string

        the name of the value

      Returns SetValidator<T, E>

      a validator for the value

      TypeError if name is undefined or null

      RangeError if name contains whitespace or is empty

    • Validates the state of a string.

      The returned validator throws an error immediately if a validation fails.

      Type Parameters

      • T extends undefined | null | string

        the type of the value

      Parameters

      • value: T

        the value

      • name: string

        the name of the value

      Returns StringValidator<T>

      a validator for the value

      TypeError if name is undefined or null

      RangeError if name contains whitespace or is empty