@metreeca/core - v0.9.22
    Preparing search index...

    Function test

    • Constrains a value with a custom predicate that words its own violation.

      Adapts an arbitrary check into a validator, folding the verdict and its message into one predicate: it returns true when the value passes, or the Trace describing the violation when it fails. Prefixing the message with a facet of its own, in braces, names the violation the way a built-in constraint names its own.

      Type Parameters

      • T

        The type of the tested value

      Parameters

      • predicate: (value: T) => true | Trace

        The predicate the value must satisfy, returning true on success or the Trace wording the violation on failure

      Returns Validator<T>

      A validator reporting the Trace returned by predicate when the value does not satisfy it