-
Notifications
You must be signed in to change notification settings - Fork 6
/
example.js
62 lines (48 loc) · 1.32 KB
/
example.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
'use strict'
const EmailValidation = require('./index')
const ev = new EmailValidation()
function displayInfos (result) {
let s = ''
if (result.valid) s += `${result.email} looks like a valid email :)`
else {
s += `${result.email} is not valid because `
if (result.errors.includes('invalid')) s += `${result.email} is an invalid email`
if (result.errors.includes('disposable')) s += `${result.domain} is disposable domain`
if (result.errors.includes('freemail')) s += `${result.domain} is a free domain`
if (result.errors.includes('blacklist')) s += `you just blacklisted it`
if (result.typo) s += `Did you mean ${result.typo}?`
}
console.log(s)
}
displayInfos(
ev.check('lol')
)
displayInfos(
ev.check('[email protected]')
)
displayInfos(
ev.check('[email protected]')
)
displayInfos(
ev.check('not@an-email')
)
displayInfos(
ev.check('[email protected]')
)
displayInfos(
ev.check('[email protected]')
)
// If check for possible typos
displayInfos(
ev.check('[email protected]')
)
// You can easily add some blacklisted domains on the fly if needed
ev.blacklist('email.io')
displayInfos(
ev.check('[email protected]')
)
// Or if you're lazy you can add an email, and it will blacklist the domain for you ;)
ev.blacklist('[email protected]')
displayInfos(
ev.check('[email protected]')
)