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

    Function object

    • Constrains an object.

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

      • entry validator — a single validator applied to every property as a [name, value] pair, so it may constrain property names as well as their values;
      • record template — a Keyed record of entries applied by property name, each validator seeing only the value, the name being already fixed by the key it is filed under.

      Templates are closed by default: properties not named by the template are rejected. Including a key wildcard entry opens the template, applying its validator to every property not explicitly named, pass to admit them unconstrained.

      Property violations are reported keyed by property name, the wildcard ones under the name of the property they were reported for. A second validator constrains the record as a whole, covering constraints spanning several properties, so both levels are stated in one call. Whole-record violations lead the report as bare messages, ahead of the record keying the property ones.

      Type Parameters

      • T

        The type of the property values

      Parameters

      • entries: Modal<Validator<readonly [string, T]>> | Keyed<Modal<Validator<T>>>

        The [name, value] entry validator or the property template; omitted or disabled validators accept the corresponding properties

      • Optionalwhole: Modal<Validator<Record<string, T>>>

        The validator applied to the record as a whole; omit or disable to constrain the properties alone

      Returns Validator<Record<string, T>>

      A validator reporting the violations the object incurs, property-wise and as a whole