this repo has no description
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

Cache the domains

authored by

JonLuca De Caro and committed by
GitHub
5b21167c 77bd574d

+12 -3
+12 -3
index.ts
··· 1 1 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 + } 3 13 4 14 // Function to detect disposable email addresses 5 15 export default async function disposableEmailDetector(email: string): Promise<boolean> { 6 16 try { 7 17 // 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(); 10 19 11 20 // Extract the domain from the email address 12 21 const domain = email.split('@')[1].toLowerCase(); // Get the domain part of the email address and convert it to lowercase