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

Function isLengthBetween

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

Source from the content-addressed store, hash-verified

8952 * @since 4.0.0
8953 */
8954export function isLengthBetween(minimum: number, maximum: number, annotations?: Annotations.Filter) {
8955 minimum = Math.max(0, Math.floor(minimum))
8956 maximum = Math.max(0, Math.floor(maximum))
8957 return makeFilter<{ readonly length: number }>(
8958 (input) => input.length >= minimum && input.length <= maximum,
8959 {
8960 expected: minimum === maximum
8961 ? `a value with a length of ${minimum}`
8962 : `a value with a length between ${minimum} and ${maximum}`,
8963
8964 representation: {
8965 id: "effect/schema/isLengthBetween",
8966 payload: { minimum, maximum }
8967 },
8968 toJsonSchema: ({ type }) =>
8969 type === "array"
8970 ? { allOf: [{ minItems: minimum }, { maxItems: maximum }] }
8971 : { allOf: [{ minLength: minimum }, { maxLength: maximum }] },
8972 toCode: () => ({ runtime: `Schema.isLengthBetween(${minimum}, ${maximum})` }),
8973 [InternalAnnotations.STRUCTURAL_ANNOTATION_KEY]: true,
8974 arbitrary: {
8975 constraint: {
8976 minLength: minimum,
8977 maxLength: maximum
8978 }
8979 },
8980 ...annotations
8981 }
8982 )
8983}
8984
8985/**
8986 * Reviver for persisted `isLengthBetween` checks.

Callers 1

Schema.tsFile · 0.85

Calls 1

makeFilterFunction · 0.85

Tested by

no test coverage detected