@samatawy/checks
    Preparing search index...

    Class ArrayCheck

    Common interface implemented by all check classes.

    Implements

    Index

    Constructors

    Properties

    key: string | number | null | undefined
    data: any
    has_value: boolean
    is_array: boolean

    Methods

    • Runs a group of array-level checks and merges their results.

      Return an array of checks from the callback. Each check can be synchronous or a promise.

      Parameters

      Returns Promise<ArrayCheck>

      const checker = await ObjectCheck.for({ tags: ['Ada'] }).check(root => [
      root.required('tags').array().check(tags => [
      tags.minLength(1),
      tags.maxLength(5)
      ])
      ]);
    • Evaluates alternative array branches and succeeds when at least one branch is valid.

      Each branch function is evaluated in isolation using cloned array state. Valid branches are then replayed on the current checker so mutations behave the same way as normal non-branch checks.

      Parameters

      Returns Promise<ArrayCheck>

      const checker = await ObjectCheck.for({ tags: ['  Ada  '] }).check(root => [
      root.required('tags').array().anyOf([
      tags => [tags.checkEach(item => [item.string().trim().minLength(2)])],
      tags => [tags.maxLength(1)]
      ])
      ]);
    • Evaluates alternative array branches and succeeds only when exactly one branch is valid.

      Each branch function is evaluated in isolation using cloned array state. The single winning branch is then replayed on the current checker so mutations behave the same way as normal non-branch checks.

      Parameters

      Returns Promise<ArrayCheck>

    • Succeeds when a bounded number of array items satisfy the provided item-level checks.

      Matching items are evaluated in isolation first. When the overall contains condition is valid, the matching item checks are replayed on the real array so mutations such as trim() or tolerant parsing still affect the input. Non-matching item errors are not merged into the final result.

      Parameters

      Returns Promise<ArrayCheck>