@@ -4,13 +4,12 @@ const defaultErrorMsg: string[] = [
44 "Username cannot be empty" ,
55 "Username too short" ,
66 "This username is too long" ,
7- "Invalid username" ,
87] ;
98
109interface OptionsParams {
1110 minLength ?: number ;
1211 maxLength ?: number ;
13- cbValidate ?: ( username : string ) => boolean ;
12+ cbValidate ?: ( username : string ) => ValidateFunctions ;
1413 errorMsg ?: ( string | null ) [ ] ;
1514}
1615
@@ -31,7 +30,7 @@ const defaultOptionsParams: OptionsParams = {
3130 * @default maxLength number: Infinity
3231 * @default cbValidate function: undefined
3332 * @info minLength cannot be greater than maxLength
34- * @description This function returns 4 errors in the following order,
33+ * @description This function returns 3 errors in the following order,
3534 *
3635 * If you want to use a default parameter, use null.
3736 *
@@ -40,7 +39,6 @@ const defaultOptionsParams: OptionsParams = {
4039 "Username cannot be empty",
4140 "Username must be between ${maxLenthUsername} and ${maxLenthUsername} characters",
4241 "Username must be between ${maxLenthUsername} and ${maxLenthUsername} characters",
43- "Invalid username",
4442];
4543 *
4644 * Create a list of errors separated by commas in strings
@@ -101,16 +99,11 @@ function validateUsername(
10199 } ;
102100 }
103101
104- if ( cbValidate && ! cbValidate ( username ) ) {
105- return {
106- isValid : false ,
107- errorMsg : getErrorMessage (
108- 3 ,
109- errorMsg ,
110- minLenthUsername ,
111- maxLenthUsername ,
112- ) ,
113- } ;
102+ const cbValidateResult : ValidateFunctions | undefined =
103+ cbValidate ?.( username ) ;
104+
105+ if ( cbValidateResult && ! cbValidateResult . isValid ) {
106+ return cbValidateResult ;
114107 }
115108
116109 return {
0 commit comments