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

Function isMaxLength

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

Source from the content-addressed store, hash-verified

8889 * @since 4.0.0
8890 */
8891export function isMaxLength(maxLength: number, annotations?: Annotations.Filter) {
8892 maxLength = Math.max(0, Math.floor(maxLength))
8893 return makeFilter<{ readonly length: number }>(
8894 (input) => input.length <= maxLength,
8895 {
8896 expected: `a value with a length of at most ${maxLength}`,
8897 representation: {
8898 id: "effect/schema/isMaxLength",
8899 payload: { maxLength }
8900 },
8901 toJsonSchema: ({ type }) => type === "array" ? { maxItems: maxLength } : { maxLength },
8902 toCode: () => ({ runtime: `Schema.isMaxLength(${maxLength})` }),
8903 [InternalAnnotations.STRUCTURAL_ANNOTATION_KEY]: true,
8904 arbitrary: {
8905 constraint: {
8906 maxLength
8907 }
8908 },
8909 ...annotations
8910 }
8911 )
8912}
8913
8914/**
8915 * Reviver for persisted `isMaxLength` checks.

Callers 1

Schema.tsFile · 0.85

Calls 1

makeFilterFunction · 0.85

Tested by

no test coverage detected