| 123456789101112131415161718192021222324252627 |
- 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 === 'integer') {
- return (value: unknown) =>
- Number.isInteger(value as number) || t('need_to_be_integer')
- }
- return () => true
- }
- }
|