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

    Class JavascriptValidatorsAbstract

    Creates validators for the Javascript API with an independent configuration.

    A factory that creates different types of validators.

    There are three kinds of validators:

    • `requireThat` for method preconditions.
    • `assertThat` for class invariants, and method postconditions.
    • `checkIf` for returning multiple validation failures.

    Implements

    Implemented by

    Index

    Constructors

    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. This error is then converted into an AssertionError. Errors unrelated to validation failures are not converted.

      Type Parameters

      • T

        the type of the value

      Parameters

      • value: T

        the value

      • Optionalname: 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. This error is then converted into an AssertionError. Errors unrelated to validation failures are not converted.

      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

      • Optionalname: 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. This error is then converted into an AssertionError. Errors unrelated to validation failures are not converted.

      Type Parameters

      • T extends undefined | null | boolean

        the type of the value

      Parameters

      • value: T

        the value

      • Optionalname: 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. This error is then converted into an AssertionError. Errors unrelated to validation failures are not converted.

      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

      • Optionalname: 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. This error is then converted into an AssertionError. Errors unrelated to validation failures are not converted.

      Type Parameters

      • T extends undefined | null | number

        the type of the value

      Parameters

      • value: T

        the value

      • Optionalname: 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. This error is then converted into an AssertionError. Errors unrelated to validation failures are not converted.

      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

      • Optionalname: 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. This error is then converted into an AssertionError. Errors unrelated to validation failures are not converted.

      Type Parameters

      • T extends undefined | null | string

        the type of the value

      Parameters

      • value: T

        the value

      • Optionalname: 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

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

      The returned validator captures errors on validation failure rather than throwing them immediately. These errors can be retrieved or thrown once the validation completes. Errors unrelated to validation failures are thrown immediately.

      Type Parameters

      • T

        the type of the value

      Parameters

      • value: T

        the value

      • Optionalname: 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 captures errors on validation failure rather than throwing them immediately. These errors can be retrieved or thrown once the validation completes. Errors unrelated to validation failures are thrown immediately.

      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

      • Optionalname: 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 captures errors on validation failure rather than throwing them immediately. These errors can be retrieved or thrown once the validation completes. Errors unrelated to validation failures are thrown immediately.

      Type Parameters

      • T extends undefined | null | boolean

        the type of the value

      Parameters

      • value: T

        the value

      • Optionalname: 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 captures errors on validation failure rather than throwing them immediately. These errors can be retrieved or thrown once the validation completes. Errors unrelated to validation failures are thrown immediately.

      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

      • Optionalname: 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 captures errors on validation failure rather than throwing them immediately. These errors can be retrieved or thrown once the validation completes. Errors unrelated to validation failures are thrown immediately.

      Type Parameters

      • T extends undefined | null | number

        the type of the value

      Parameters

      • value: T

        the value

      • Optionalname: 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 captures errors on validation failure rather than throwing them immediately. These errors can be retrieved or thrown once the validation completes. Errors unrelated to validation failures are thrown immediately.

      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

      • Optionalname: 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 captures errors on validation failure rather than throwing them immediately. These errors can be retrieved or thrown once the validation completes. Errors unrelated to validation failures are thrown immediately.

      Type Parameters

      • T extends undefined | null | string

        the type of the value

      Parameters

      • value: T

        the value

      • Optionalname: 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

    • Returns a new factory instance with an independent configuration. This method is commonly used to inherit and update contextual information from the original factory before passing it into a nested operation. For example,

      JavascriptValidators copy = validators.copy();
      copy.getContext().put(json.toString(), "json");
      nestedOperation(copy);

      Returns JavascriptValidators

      a copy of this factory

    • Returns the contextual information inherited by validators created out by this factory. The contextual information is a map of key-value pairs that can provide more details about validation failures. For example, if the message is "Password may not be empty" and the map contains the key-value pair {"username": "john.smith"}, the error message would be:

      Password may not be empty
      username: john.smith

      Returns Map<string, unknown>

      an unmodifiable map from each entry's name to its value

    • Removes the contextual information of validators created by this factory.

      Parameters

      • name: string

        the parameter name

      Returns this

      this

      TypeError if name is undefined or null

      RangeError if name:

      • contains whitespace
      • is empty

    • 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

    • Sets the contextual information for validators created by this factory.

      This method adds contextual information to error messages. The contextual information is stored as key-value pairs in a map. Values set by this method may be overridden by ValidatorComponent.withContext.

      Parameters

      • value: unknown

        the value of the entry

      • name: string

        the name of an entry

      Returns this

      this

      TypeError if name is undefined or null

      RangeError if:

      • name is empty
      • name contains whitespace
      • name is already in use by the value being validated or the validator context