TypeAssert.ts 575 B

123456789101112131415161718192021
  1. import type {AssertRule} from "~/types/interfaces";
  2. import { useI18n } from 'vue-i18n';
  3. import ValidationUtils from "~/services/utils/validationUtils";
  4. export class TypeAssert implements AssertRule {
  5. supports(key: string): boolean {
  6. return key === 'type';
  7. }
  8. createRule(criteria: string): (value: any) => true | string {
  9. const validationUtils = new ValidationUtils()
  10. const { t } = useI18n();
  11. if (criteria === 'email') {
  12. return (email: string) =>
  13. validationUtils.validEmail(email) || t('email_error');
  14. }
  15. return () => true;
  16. }
  17. }