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

    Represents a value that is being validated.

    This class is not intended to replace undefined or null references but to record additional information alongside them.

    Instead of throwing an error when an undefined or null value is accessed, the system marks it as invalid and continues to record validation failures.

    Type Parameters

    • T

      the type of the value

    Index

    Constructors

    Methods

    • Consumes the value if it is valid. If the value is invalid, no action is taken.

      Parameters

      • consumer: (value: T) => void

        consumes the value if it is valid

      Returns void

    • Applies a function to the value if it is valid. If the value is invalid, no action is taken.

      Type Parameters

      • U

        the type of value returned by the mapper

      Parameters

      • mapper: (value: T) => U

        the function to apply to the value if it is valid

      Returns ValidationTarget<U>

      this if the value is invalid; otherwise, a MaybeInvalid instance wrapping the result of applying the mapper to the value

    • Returns the valid value, or a default value if invalid. A value of null does not hold any special significance. It does not imply that the value is invalid.

      Parameters

      • defaultValue: T

        a value

      Returns T

      the valid value, or defaultValue if the value is invalid

    • Returns the valid value, or a default value if invalid. A value of null does not hold any special significance. It does not imply that the value is invalid.

      Parameters

      • defaultValue: null | T

        a value

      Returns null | T

      the valid value, or defaultValue if the value is invalid

    • Returns the valid value, or a default value if invalid. A value of null does not hold any special significance. It does not imply that the value is invalid.

      Parameters

      • defaultValue: () => T

        a supplier that returns the default value

      Returns T

      the valid value, or defaultValue if the value is invalid

    • Returns the value or throws an error if invalid.

      Parameters

      • errorSupplier: () => Error

        returns the error to throw if the value is invalid

      Returns T

      the value

      U if the value is invalid