MCPcopy Create free account
hub / github.com/Effect-TS/effect / isMaxLength

Function isMaxLength

packages/effect/src/Schema.ts:8571–8596  ·  view source on GitHub ↗
(maxLength: number, annotations?: Annotations.Filter)

Source from the content-addressed store, hash-verified

8569 * @since 4.0.0
8570 */
8571export function isMaxLength(maxLength: number, annotations?: Annotations.Filter) {
8572 maxLength = normalizeCardinality(maxLength)
8573 return makeFilter<{ readonly length: number }>(
8574 (input) => input.length <= maxLength,
8575 {
8576 expected: `a value with a length of at most ${maxLength}`,
8577 representation: {
8578 id: "effect/schema/isMaxLength",
8579 payload: { maxLength }
8580 },
8581 toJsonSchema: ({ type }) =>
8582 type === "string"
8583 ? maxLength === 0 ? { maxLength } : [{ maxLength }, true]
8584 : type === "array"
8585 ? { maxItems: maxLength }
8586 : type === undefined
8587 ? [{ maxLength, maxItems: maxLength }, true]
8588 : [{}, true],
8589 [InternalAnnotations.STRUCTURAL_ANNOTATION_KEY]: true,
8590 arbitraryConstraint: {
8591 maxLength
8592 },
8593 ...annotations
8594 }
8595 )
8596}
8597/**
8598 * Validates that a value's length is within the specified range. Works with
8599 * strings and arrays.

Callers 1

Calls 2

normalizeCardinalityFunction · 0.85
makeFilterFunction · 0.70

Tested by

no test coverage detected