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

    Function array

    • Constrains an array.

      Applies element-wise constraints in either of the two modes of the isArray guard of @metreeca/core:

      • element validator — a single validator applied to every element in turn;
      • tuple template — an array of validators applied positionally, requiring the array to match it in length.

      Element violations are reported keyed by element position ("2"). A second validator constrains the array as a whole, covering cardinality, membership, and the like, so both levels are stated in one call. Whole-array violations lead the report as bare messages, ahead of the record keying the element ones.

      Type Parameters

      • T

        The element type of the array

      Parameters

      • elements: Modal<Validator<T>> | readonly Modal<Validator<T>>[]

        The element validator or positional tuple template; omitted or disabled validators accept the corresponding elements

      • Optionalarray: Modal<Validator<readonly T[]>>

        The validator applied to the array as a whole; omit or disable to constrain the elements alone

      Returns Validator<readonly T[]>

      A validator reporting the violations the array incurs, element-wise and as a whole