11import i18n from 'i18next' ;
22
3- /* eslint-disable */
3+ // eslint-disable-next-line max-len
44const 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 } $ / ;
76
87type Email = { email : string } ;
98type Username = { username : string } ;
@@ -25,7 +24,7 @@ export type FormErrors = Partial<
2524/** Processes form & mutates errors to add any `username` & `email` errors */
2625function validateUsernameEmail (
2726 formProps : Partial < UsernameAndEmail > ,
28- errors : Partial < FormErrors >
27+ errors : FormErrors
2928) {
3029 if ( ! formProps . username ) {
3130 errors . username = i18n . t ( 'ReduxFormUtils.errorEmptyUsername' ) ;
@@ -45,7 +44,7 @@ function validateUsernameEmail(
4544/** Processes form & mutates errors to add any `password` and `confirmPassword` errors */
4645function validatePasswords (
4746 formProps : Partial < PasswordsConfirm > ,
48- errors : Partial < FormErrors >
47+ errors : FormErrors
4948) {
5049 if ( ! formProps . password ) {
5150 errors . password = i18n . t ( 'ReduxFormUtils.errorEmptyPassword' ) ;
@@ -69,13 +68,12 @@ function validatePasswords(
6968
7069// Account Form:
7170export type AccountForm = UsernameAndEmail & CurrentPassword & NewPassword ;
72- export type AccountFormErrors = Partial < AccountForm > ;
7371
7472/** Validation for the Account Form */
7573export function validateSettings (
7674 formProps : Partial < AccountForm >
77- ) : AccountFormErrors {
78- const errors : AccountFormErrors = { } ;
75+ ) : Partial < AccountForm > {
76+ const errors : Partial < AccountForm > = { } ;
7977
8078 validateUsernameEmail ( formProps , errors ) ;
8179
@@ -96,11 +94,12 @@ export function validateSettings(
9694
9795// Login form:
9896export type LoginForm = UsernameAndEmail & Password ;
99- export type LoginFormErrors = Partial < LoginForm > ;
10097
10198/** 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 > = { } ;
104103 if ( ! formProps . email && ! formProps . username ) {
105104 errors . email = i18n . t ( 'ReduxFormUtils.errorEmptyEmailorUserName' ) ;
106105 }
@@ -111,26 +110,24 @@ export function validateLogin(formProps: Partial<LoginForm>): LoginFormErrors {
111110}
112111
113112export type NewPasswordForm = PasswordsConfirm ;
114- export type NewPasswordFormErrors = Partial < NewPasswordForm > ;
115113
116114/** Validation for the New Password Form */
117115export function validateNewPassword (
118116 formProps : Partial < NewPasswordForm >
119- ) : NewPasswordFormErrors {
117+ ) : Partial < NewPasswordForm > {
120118 const errors = { } ;
121119 validatePasswords ( formProps , errors ) ;
122120 return errors ;
123121}
124122
125123// Signup Form:
126124export type SignupForm = UsernameAndEmail & PasswordsConfirm ;
127- export type SignupFormErrors = Partial < SignupForm > ;
128125
129126/** Validation for the Signup Form */
130127export function validateSignup (
131128 formProps : Partial < SignupForm >
132- ) : SignupFormErrors {
133- const errors : SignupFormErrors = { } ;
129+ ) : Partial < SignupForm > {
130+ const errors = { } ;
134131
135132 validateUsernameEmail ( formProps , errors ) ;
136133 validatePasswords ( formProps , errors ) ;
@@ -140,13 +137,12 @@ export function validateSignup(
140137
141138// Reset Password Form:
142139export type ResetPasswordForm = Email ;
143- export type ResetPasswordFormErrors = Partial < ResetPasswordForm > ;
144140
145141/** Validation for the Reset Password Form */
146142export function validateResetPassword (
147143 formProps : Partial < ResetPasswordForm >
148- ) : ResetPasswordFormErrors {
149- const errors : ResetPasswordFormErrors = { } ;
144+ ) : Partial < ResetPasswordForm > {
145+ const errors : Partial < ResetPasswordForm > = { } ;
150146 if ( ! formProps . email ) {
151147 errors . email = i18n . t ( 'ReduxFormUtils.errorEmptyEmail' ) ;
152148 } else if ( ! formProps . email . match ( EMAIL_REGEX ) ) {
0 commit comments