Hyperlinkv0.8.0-beta.28

Schema

Schema.isLengthBetweenfunctioneffect/Schema.ts:8091
(
  minimum: number,
  maximum: number,
  annotations?: Annotations.Filter
): SchemaAST.Filter<{ readonly length: number }>

Validates that a value's length is within the specified range. Works with strings and arrays.

Details

JSON Schema:

This check corresponds to minLength/maxLength constraints for strings or minItems/maxItems constraints for arrays in JSON Schema.

Arbitrary:

When generating test data with fast-check, this applies minLength and maxLength constraints to ensure generated strings or arrays have a length within the specified range.

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