Skip to content

Commit a5ce9ea

Browse files
committed
improve regex
1 parent 63be139 commit a5ce9ea

File tree

4 files changed

+10
-15
lines changed

4 files changed

+10
-15
lines changed

package.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,11 @@
2020
},
2121
"dependencies": {
2222
"@types/mailcheck": "^1.1.31",
23+
"@types/validator": "^12.0.1",
2324
"axios": "^0.19.2",
2425
"lodash": "^4.17.15",
25-
"mailcheck": "^1.1.1"
26+
"mailcheck": "^1.1.1",
27+
"validator": "^12.2.0"
2628
},
2729
"devDependencies": {
2830
"@types/eslint": "^6.1.1",

src/disposable/disposable.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,5 +33,6 @@ export const checkDisposable = async (
3333
domain: string
3434
): Promise<string | undefined> => {
3535
if (disposableDomains.size === 0) await loadDisposableDomains()
36-
if (disposableDomains.has(domain)) return 'Is disposable email'
36+
if (disposableDomains.has(domain))
37+
return 'Email was created using a disposable email service'
3738
}

src/index.ts

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
import isEmail from 'validator/lib/isEmail'
12
import { OutputFormat, createOutput } from './output/output'
23
import { checkTypo } from './typo/typo'
34
import { getBestMx } from './dns/dns'
@@ -15,26 +16,18 @@ export async function validate(
1516
recipient: string,
1617
sender: string = '[email protected]'
1718
): Promise<OutputFormat> {
18-
if (!/^\S+@\S+$/.test(recipient)) {
19-
return createOutput('regex')
20-
}
19+
if (!isEmail(recipient)) return createOutput('regex')
2120

2221
const typoResponse = await checkTypo(recipient)
23-
if (typoResponse) {
24-
return createOutput('typo', typoResponse)
25-
}
22+
if (typoResponse) return createOutput('typo', typoResponse)
2623

2724
const domain = recipient.split('@')[1]
2825

2926
const disposableResponse = await checkDisposable(domain)
30-
if (disposableResponse) {
31-
return createOutput('disposable', disposableResponse)
32-
}
27+
if (disposableResponse) return createOutput('disposable', disposableResponse)
3328

3429
const mx = await getBestMx(domain)
35-
if (!mx) {
36-
return createOutput('mx', 'MX record not found')
37-
}
30+
if (!mx) return createOutput('mx', 'MX record not found')
3831

3932
return checkSMTP(sender, recipient, mx.exchange)
4033
}

src/output/output.ts

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,6 @@ const NullOutputFormat = {
1010
typo: { valid: true } as ValidatorOutput,
1111
disposable: { valid: true } as ValidatorOutput,
1212
mx: { valid: true } as ValidatorOutput,
13-
dns: { valid: true } as ValidatorOutput,
1413
smtp: { valid: true } as ValidatorOutput,
1514
},
1615
}

0 commit comments

Comments
 (0)