import type { AssertRule } from '~/types/interfaces' import { useI18n } from 'vue-i18n' import ValidationUtils from '~/services/utils/validationUtils' export class TypeAssert implements AssertRule { supports(key: string): boolean { return key === 'type' } createRule(criteria: string): (value: unknown) => true | string { const validationUtils = new ValidationUtils() const { t } = useI18n() if (criteria === 'email') { return (email: unknown) => (typeof email === 'string' && validationUtils.validEmail(email)) || t('email_error') } if (criteria === 'url') { return (url: unknown) => url === null || (typeof url === 'string' && validationUtils.validUrl(url)) || t('url_error') } if (criteria === 'integer') { return (value: unknown) => Number.isInteger(value as number) || t('need_to_be_integer') } return () => true } }