File tree Expand file tree Collapse file tree 1 file changed +12
-3
lines changed
Expand file tree Collapse file tree 1 file changed +12
-3
lines changed Original file line number Diff line number Diff line change 11import 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
515export 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
You can’t perform that action at this time.
0 commit comments