Hyperlinkv0.8.0-beta.28

Schema

Schema.isPropertiesLengthBetweenfunctioneffect/Schema.ts:8346
(
  minimum: number,
  maximum: number,
  annotations?: Annotations.Filter
): SchemaAST.Filter<object>

Validates that an object contains between minimum and maximum properties (inclusive). This includes both string and symbol keys when counting properties.

Details

JSON Schema:

This check corresponds to minProperties and maxProperties constraints in JSON Schema.

Arbitrary:

When generating test data with fast-check, this applies node-local minLength and maxLength constraints. Object generators interpret them as the final number of own properties.

Object checks
Source effect/Schema.ts:834625 lines
export function isPropertiesLengthBetween(minimum: number, maximum: number, annotations?: Annotations.Filter) {
  minimum = Math.max(0, Math.floor(minimum))
  maximum = Math.max(0, Math.floor(maximum))
  return makeFilter<object>(
    (input) => Reflect.ownKeys(input).length >= minimum && Reflect.ownKeys(input).length <= maximum,
    {
      expected: minimum === maximum
        ? `a value with exactly ${minimum === 1 ? "1 entry" : `${minimum} entries`}`
        : `a value with between ${minimum} and ${maximum} entries`,
      meta: {
        _tag: "isPropertiesLengthBetween",
        minimum,
        maximum
      },
      [SchemaAST.STRUCTURAL_ANNOTATION_KEY]: true,
      arbitrary: {
        constraint: {
          minLength: minimum,
          maxLength: maximum
        }
      },
      ...annotations
    }
  )
}
Referenced by 1 symbols