File tree Expand file tree Collapse file tree 5 files changed +53
-5
lines changed Expand file tree Collapse file tree 5 files changed +53
-5
lines changed Original file line number Diff line number Diff line change @@ -19,7 +19,7 @@ export async function validate(
19
19
}
20
20
21
21
if ( options . validateTypo ) {
22
- const typoResponse = await checkTypo ( email )
22
+ const typoResponse = await checkTypo ( email , options . additionalTopLevelDomains )
23
23
if ( typoResponse ) return createOutput ( 'typo' , typoResponse )
24
24
}
25
25
Original file line number Diff line number Diff line change @@ -17,8 +17,12 @@ type Options = {
17
17
validateSMTP : boolean
18
18
}
19
19
20
- export type ValidatorOptions = Partial < Options > & { email : string }
21
- type ValidatorOptionsFinal = Options & { email : string }
20
+ type MailCheckOptions = {
21
+ additionalTopLevelDomains ?: string [ ]
22
+ }
23
+
24
+ export type ValidatorOptions = Partial < Options > & { email : string } & MailCheckOptions
25
+ type ValidatorOptionsFinal = Options & { email : string } & MailCheckOptions
22
26
23
27
export function getOptions (
24
28
emailOrOptions : string | ValidatorOptions
Original file line number Diff line number Diff line change @@ -6,15 +6,21 @@ type TypoSuggestion = {
6
6
full : string
7
7
}
8
8
9
- export const checkTypo = async ( email : string ) : Promise < string | undefined > =>
9
+ export const checkTypo = async ( email : string , additionalTLDs ?: string [ ] ) : Promise < string | undefined > =>
10
10
new Promise ( r =>
11
+ {
12
+ let topLevelDomains = undefined
13
+ if ( additionalTLDs && additionalTLDs . length > 0 ) {
14
+ topLevelDomains = [ ...mailCheck . defaultTopLevelDomains , ...additionalTLDs ]
15
+ }
11
16
mailCheck . run ( {
12
17
email,
18
+ topLevelDomains : topLevelDomains ,
13
19
suggested : ( suggestion : TypoSuggestion ) => {
14
20
r ( `Likely typo, suggested email: ${ suggestion . full } ` )
15
21
} ,
16
22
empty : function ( ) {
17
23
r ( )
18
24
} ,
19
25
} )
20
- )
26
+ } )
Original file line number Diff line number Diff line change @@ -316,3 +316,26 @@ Object {
316
316
},
317
317
}
318
318
` ;
319
+
320
+ exports [` validation tests passes with custom TLD 1` ] = `
321
+ Object {
322
+ " valid" : true ,
323
+ " validators" : Object {
324
+ " disposable" : Object {
325
+ " valid" : true ,
326
+ },
327
+ " mx" : Object {
328
+ " valid" : true ,
329
+ },
330
+ " regex" : Object {
331
+ " valid" : true ,
332
+ },
333
+ " smtp" : Object {
334
+ " valid" : true ,
335
+ },
336
+ " typo" : Object {
337
+ " valid" : true ,
338
+ },
339
+ },
340
+ }
341
+ ` ;
Original file line number Diff line number Diff line change @@ -120,4 +120,19 @@ describe('validation tests', () => {
120
120
} ,
121
121
elevenSeconds
122
122
)
123
+
124
+ it (
125
+ 'passes with custom TLD' ,
126
+ async ( ) => {
127
+ const res = await validate ( {
128
+ email : 'info@utob.ir' ,
129
+ validateSMTP : false ,
130
+ additionalTopLevelDomains : [ 'ir' ]
131
+ } )
132
+ expect ( res . valid ) . toBe ( true )
133
+ expect ( every ( values ( res . validators ) , x => x && x . valid ) ) . toBe ( true )
134
+ expect ( res ) . toMatchSnapshot ( )
135
+ } ,
136
+ elevenSeconds
137
+ )
123
138
} )
You can’t perform that action at this time.
0 commit comments