-
-
Notifications
You must be signed in to change notification settings - Fork 2
/
index.js
43 lines (43 loc) · 2.24 KB
/
index.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
"use strict";
var __awaiter = (this?.__awaiter) || function (thisArg, _arguments, P, generator) {
function adopt(value) { return value instanceof P ? value : new P(function (resolve) { resolve(value); }); }
return new (P || (P = Promise))(function (resolve, reject) {
function fulfilled(value) { try { step(generator.next(value)); } catch (e) { reject(e); } }
function rejected(value) { try { step(generator["throw"](value)); } catch (e) { reject(e); } }
function step(result) { result.done ? resolve(result.value) : adopt(result.value).then(fulfilled, rejected); }
step((generator = generator.apply(thisArg, _arguments || [])).next());
});
};
var __importDefault = (this?.__importDefault) || function (mod) {
return (mod?.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
const promises_1 = __importDefault(require("fs/promises"));
const path_1 = __importDefault(require("path"));
// Function to detect disposable email addresses
function disposableEmailDetector(email) {
return __awaiter(this, void 0, void 0, function* () {
try {
// Load the list of disposable email domains from the index.json file
const disposableDomainsBuffer = yield promises_1.default.readFile(path_1.default.join(__dirname, 'index.json'));
const disposableDomains = JSON.parse(disposableDomainsBuffer.toString());
// Extract the domain from the email address
const domain = email.split('@')[1].toLowerCase(); // Get the domain part of the email address and convert it to lowercase
// Check if the domain is in the list of disposable domains
return disposableDomains.includes(domain);
}
catch (error) {
if (error.code === 'ENOENT') {
console.error('index.json not found. Please create it with disposable domains.');
}
else if (error instanceof SyntaxError) {
console.error('Invalid JSON format in index.json. Please correct the file.');
}
else {
console.error('Unexpected error:', error);
}
return false;
}
});
}
exports.default = disposableEmailDetector;