Hyperlinkv0.8.0-beta.28

Schema

Schema.isSizeBetweenfunctioneffect/Schema.ts:8219
(
  minimum: number,
  maximum: number,
  annotations?: Annotations.Filter
): SchemaAST.Filter<{ readonly size: number }>

Validates that a value's size is within the specified range. Works with values that have a size property, such as Set or Map.

Details

JSON Schema:

This check does not have a direct JSON Schema equivalent, as it applies to values with a size property rather than standard JSON Schema types.

Arbitrary:

When generating test data with fast-check, this applies node-local minLength and maxLength constraints. Generators for values with a final .size, such as sets and maps, interpret them as final cardinality.

Size checks
Source effect/Schema.ts:821925 lines
export function isSizeBetween(minimum: number, maximum: number, annotations?: Annotations.Filter) {
  minimum = Math.max(0, Math.floor(minimum))
  maximum = Math.max(0, Math.floor(maximum))
  return makeFilter<{ readonly size: number }>(
    (input) => input.size >= minimum && input.size <= maximum,
    {
      expected: minimum === maximum
        ? `a value with a size of ${minimum}`
        : `a value with a size between ${minimum} and ${maximum}`,
      meta: {
        _tag: "isSizeBetween",
        minimum,
        maximum
      },
      [SchemaAST.STRUCTURAL_ANNOTATION_KEY]: true,
      arbitrary: {
        constraint: {
          minLength: minimum,
          maxLength: maximum
        }
      },
      ...annotations
    }
  )
}
Referenced by 1 symbols