Hyperlinkv0.8.0-beta.28

Schema

Schema.isMaxLengthfunctioneffect/Schema.ts:8050
(maxLength: number, annotations?: Annotations.Filter): SchemaAST.Filter<{
  readonly length: number
}>

Validates that a value has at most the specified length. Works with strings and arrays.

Details

JSON Schema:

This check corresponds to the maxLength constraint for strings or the maxItems constraint for arrays in JSON Schema.

Arbitrary:

When generating test data with fast-check, this applies a maxLength constraint to ensure generated strings or arrays have at most the required length.

Length checks
Source effect/Schema.ts:805020 lines
export function isMaxLength(maxLength: number, annotations?: Annotations.Filter) {
  maxLength = Math.max(0, Math.floor(maxLength))
  return makeFilter<{ readonly length: number }>(
    (input) => input.length <= maxLength,
    {
      expected: `a value with a length of at most ${maxLength}`,
      meta: {
        _tag: "isMaxLength",
        maxLength
      },
      [SchemaAST.STRUCTURAL_ANNOTATION_KEY]: true,
      arbitrary: {
        constraint: {
          maxLength
        }
      },
      ...annotations
    }
  )
}
Referenced by 1 symbols