MaxAssert.ts 338 B

123456789101112
  1. import type {AssertRule} from "~/types/interfaces";
  2. export class MaxAssert implements AssertRule {
  3. supports(key: string): boolean {
  4. return key === 'max';
  5. }
  6. createRule(criteria: number): (value: string) => true | string {
  7. return (value: string) =>
  8. value.length <= criteria || `Maximum ${criteria} caractères`;
  9. }
  10. }