1
1
import i18n from 'i18next' ;
2
2
3
- /* eslint-disable */
3
+ // eslint-disable-next-line max-len
4
4
const EMAIL_REGEX = / ^ ( ( [ ^ < > ( ) [ \] \\ . , ; : \s @ " ] + ( \. [ ^ < > ( ) [ \] \\ . , ; : \s @ " ] + ) * ) | ( " .+ " ) ) @ ( ( \[ [ 0 - 9 ] { 1 , 3 } \. [ 0 - 9 ] { 1 , 3 } \. [ 0 - 9 ] { 1 , 3 } \. [ 0 - 9 ] { 1 , 3 } ] ) | ( ( [ a - z A - Z \- 0 - 9 ] + \. ) + [ a - z A - Z ] { 2 , } ) ) $ / i;
5
- const USERNAME_REGEX = / ^ [ a - z A - Z 0 - 9 . _ - ] { 1 , 20 } $ /
6
- /* eslint-enable */
5
+ const USERNAME_REGEX = / ^ [ a - z A - Z 0 - 9 . _ - ] { 1 , 20 } $ / ;
7
6
8
7
type Email = { email : string } ;
9
8
type Username = { username : string } ;
@@ -25,7 +24,7 @@ export type FormErrors = Partial<
25
24
/** Processes form & mutates errors to add any `username` & `email` errors */
26
25
function validateUsernameEmail (
27
26
formProps : Partial < UsernameAndEmail > ,
28
- errors : Partial < FormErrors >
27
+ errors : FormErrors
29
28
) {
30
29
if ( ! formProps . username ) {
31
30
errors . username = i18n . t ( 'ReduxFormUtils.errorEmptyUsername' ) ;
@@ -45,7 +44,7 @@ function validateUsernameEmail(
45
44
/** Processes form & mutates errors to add any `password` and `confirmPassword` errors */
46
45
function validatePasswords (
47
46
formProps : Partial < PasswordsConfirm > ,
48
- errors : Partial < FormErrors >
47
+ errors : FormErrors
49
48
) {
50
49
if ( ! formProps . password ) {
51
50
errors . password = i18n . t ( 'ReduxFormUtils.errorEmptyPassword' ) ;
@@ -69,13 +68,12 @@ function validatePasswords(
69
68
70
69
// Account Form:
71
70
export type AccountForm = UsernameAndEmail & CurrentPassword & NewPassword ;
72
- export type AccountFormErrors = Partial < AccountForm > ;
73
71
74
72
/** Validation for the Account Form */
75
73
export function validateSettings (
76
74
formProps : Partial < AccountForm >
77
- ) : AccountFormErrors {
78
- const errors : AccountFormErrors = { } ;
75
+ ) : Partial < AccountForm > {
76
+ const errors : Partial < AccountForm > = { } ;
79
77
80
78
validateUsernameEmail ( formProps , errors ) ;
81
79
@@ -96,11 +94,12 @@ export function validateSettings(
96
94
97
95
// Login form:
98
96
export type LoginForm = UsernameAndEmail & Password ;
99
- export type LoginFormErrors = Partial < LoginForm > ;
100
97
101
98
/** Validation for the Login Form */
102
- export function validateLogin ( formProps : Partial < LoginForm > ) : LoginFormErrors {
103
- const errors : LoginFormErrors = { } ;
99
+ export function validateLogin (
100
+ formProps : Partial < LoginForm >
101
+ ) : Partial < LoginForm > {
102
+ const errors : Partial < LoginForm > = { } ;
104
103
if ( ! formProps . email && ! formProps . username ) {
105
104
errors . email = i18n . t ( 'ReduxFormUtils.errorEmptyEmailorUserName' ) ;
106
105
}
@@ -111,26 +110,24 @@ export function validateLogin(formProps: Partial<LoginForm>): LoginFormErrors {
111
110
}
112
111
113
112
export type NewPasswordForm = PasswordsConfirm ;
114
- export type NewPasswordFormErrors = Partial < NewPasswordForm > ;
115
113
116
114
/** Validation for the New Password Form */
117
115
export function validateNewPassword (
118
116
formProps : Partial < NewPasswordForm >
119
- ) : NewPasswordFormErrors {
117
+ ) : Partial < NewPasswordForm > {
120
118
const errors = { } ;
121
119
validatePasswords ( formProps , errors ) ;
122
120
return errors ;
123
121
}
124
122
125
123
// Signup Form:
126
124
export type SignupForm = UsernameAndEmail & PasswordsConfirm ;
127
- export type SignupFormErrors = Partial < SignupForm > ;
128
125
129
126
/** Validation for the Signup Form */
130
127
export function validateSignup (
131
128
formProps : Partial < SignupForm >
132
- ) : SignupFormErrors {
133
- const errors : SignupFormErrors = { } ;
129
+ ) : Partial < SignupForm > {
130
+ const errors = { } ;
134
131
135
132
validateUsernameEmail ( formProps , errors ) ;
136
133
validatePasswords ( formProps , errors ) ;
@@ -140,13 +137,12 @@ export function validateSignup(
140
137
141
138
// Reset Password Form:
142
139
export type ResetPasswordForm = Email ;
143
- export type ResetPasswordFormErrors = Partial < ResetPasswordForm > ;
144
140
145
141
/** Validation for the Reset Password Form */
146
142
export function validateResetPassword (
147
143
formProps : Partial < ResetPasswordForm >
148
- ) : ResetPasswordFormErrors {
149
- const errors : ResetPasswordFormErrors = { } ;
144
+ ) : Partial < ResetPasswordForm > {
145
+ const errors : Partial < ResetPasswordForm > = { } ;
150
146
if ( ! formProps . email ) {
151
147
errors . email = i18n . t ( 'ReduxFormUtils.errorEmptyEmail' ) ;
152
148
} else if ( ! formProps . email . match ( EMAIL_REGEX ) ) {
0 commit comments