| 8889 | * @since 4.0.0 |
| 8890 | */ |
| 8891 | export 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. |