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

Function isBetweenLength

packages/effect/src/Schema.ts:8621–8658  ·  view source on GitHub ↗
(minimum: number, maximum: number, annotations?: Annotations.Filter)

Source from the content-addressed store, hash-verified

8619 * @since 4.0.0
8620 */
8621export function isBetweenLength(minimum: number, maximum: number, annotations?: Annotations.Filter) {
8622 minimum = normalizeCardinality(minimum)
8623 maximum = normalizeCardinality(maximum)
8624 return makeFilter<{ readonly length: number }>(
8625 (input) => input.length >= minimum && input.length <= maximum,
8626 {
8627 expected: minimum === maximum
8628 ? `a value with a length of ${minimum}`
8629 : `a value with a length between ${minimum} and ${maximum}`,
8630
8631 representation: {
8632 id: "effect/schema/isBetweenLength",
8633 payload: { minimum, maximum }
8634 },
8635 toJsonSchema: ({ type }) =>
8636 type === "string"
8637 ? maximum === 0 || Math.ceil(minimum / 2) > maximum
8638 ? { minLength: Math.ceil(minimum / 2), maxLength: maximum }
8639 : [{ minLength: Math.ceil(minimum / 2), maxLength: maximum }, true]
8640 : type === "array"
8641 ? { minItems: minimum, maxItems: maximum }
8642 : type === undefined
8643 ? [{
8644 minLength: Math.ceil(minimum / 2),
8645 maxLength: maximum,
8646 minItems: minimum,
8647 maxItems: maximum
8648 }, true]
8649 : [{}, true],
8650 [InternalAnnotations.STRUCTURAL_ANNOTATION_KEY]: true,
8651 arbitraryConstraint: {
8652 minLength: minimum,
8653 maxLength: maximum
8654 },
8655 ...annotations
8656 }
8657 )
8658}
8659/**
8660 * Validates that a string contains at least the specified number of Unicode code points.
8661 *

Callers 2

Schema.tsFile · 0.85

Calls 2

normalizeCardinalityFunction · 0.85
makeFilterFunction · 0.70

Tested by

no test coverage detected