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(
1919 }
2020
2121 if ( options . validateTypo ) {
22- const typoResponse = await checkTypo ( email )
22+ const typoResponse = await checkTypo ( email , options . additionalTopLevelDomains )
2323 if ( typoResponse ) return createOutput ( 'typo' , typoResponse )
2424 }
2525
Original file line number Diff line number Diff line change @@ -17,8 +17,12 @@ type Options = {
1717 validateSMTP : boolean
1818}
1919
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
2226
2327export function getOptions (
2428 emailOrOptions : string | ValidatorOptions
Original file line number Diff line number Diff line change @@ -6,15 +6,21 @@ type TypoSuggestion = {
66 full : string
77}
88
9- export const checkTypo = async ( email : string ) : Promise < string | undefined > =>
9+ export const checkTypo = async ( email : string , additionalTLDs ?: string [ ] ) : Promise < string | undefined > =>
1010 new Promise ( r =>
11+ {
12+ let topLevelDomains = undefined
13+ if ( additionalTLDs && additionalTLDs . length > 0 ) {
14+ topLevelDomains = [ ...mailCheck . defaultTopLevelDomains , ...additionalTLDs ]
15+ }
1116 mailCheck . run ( {
1217 email,
18+ topLevelDomains : topLevelDomains ,
1319 suggested : ( suggestion : TypoSuggestion ) => {
1420 r ( `Likely typo, suggested email: ${ suggestion . full } ` )
1521 } ,
1622 empty : function ( ) {
1723 r ( )
1824 } ,
1925 } )
20- )
26+ } )
Original file line number Diff line number Diff line change @@ -316,3 +316,26 @@ Object {
316316 },
317317}
318318` ;
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', () => {
120120 } ,
121121 elevenSeconds
122122 )
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+ )
123138} )
You can’t perform that action at this time.
0 commit comments