Skip to content

Commit 5350651

Browse files
authored
Merge pull request #3 from jonluca/patch-1
Cache the domains
2 parents 77bd574 + 5b21167 commit 5350651

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

index.ts

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,21 @@
11
import fs from 'fs/promises';
2-
import Path from 'path';
2+
import path from 'path';
3+
4+
let cachedDomains: string[] | undefined = undefined;
5+
6+
const loadDomains = async () => {
7+
if(cachedDomains) return cachedDomains;
8+
const disposableDomainsBuffer = await fs.readFile(path.join(__dirname, 'index.json'));
9+
const disposableDomains = JSON.parse(disposableDomainsBuffer.toString());
10+
cachedDomains = disposableDomains;
11+
return disposableDomains;
12+
}
313

414
// Function to detect disposable email addresses
515
export default async function disposableEmailDetector(email: string): Promise<boolean> {
616
try {
717
// Load the list of disposable email domains from the index.json file
8-
const disposableDomainsBuffer = await fs.readFile(Path.join(__dirname, 'index.json'));
9-
const disposableDomains = JSON.parse(disposableDomainsBuffer.toString());
18+
const disposableDomains = await loadDomains();
1019

1120
// Extract the domain from the email address
1221
const domain = email.split('@')[1].toLowerCase(); // Get the domain part of the email address and convert it to lowercase

0 commit comments

Comments
 (0)