this repo has no description
0
fork

Configure Feed

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

fix bug

+164 -44
-1
index.js
··· 39 39 const URL = github ? "https://raw.githubusercontent.com/IntegerAlex/disposable-email-detector/refs/heads/main/index.json" : url; 40 40 if (!URL) 41 41 throw new ExternalSourceError(); 42 - console.info(`Loading disposable domains from ${URL}`); 43 42 try { 44 43 const response = yield fetch(URL); 45 44 const disposableDomains = yield response.json();
+59 -43
index.ts
··· 1 - import fs from 'fs/promises'; 2 - import path from 'path'; 1 + import fs from "fs/promises"; 2 + import path from "path"; 3 3 4 4 let cachedDomains: string[] | undefined = undefined; 5 5 6 6 const loadDomains = async () => { 7 - if(cachedDomains) return cachedDomains; 8 - const disposableDomainsBuffer = await fs.readFile(path.join(__dirname, 'index.json')); 7 + if (cachedDomains) return cachedDomains; 8 + const disposableDomainsBuffer = await fs.readFile( 9 + path.join(__dirname, "index.json") 10 + ); 9 11 const disposableDomains = JSON.parse(disposableDomainsBuffer.toString()); 10 12 cachedDomains = disposableDomains; 11 13 return disposableDomains; 12 - } 14 + }; 13 15 14 16 export class ExternalSourceError extends Error { 15 - constructor(message: string = 'URL must be provided when loading from external source') { 17 + constructor( 18 + message: string = "URL must be provided when loading from external source" 19 + ) { 16 20 super(message); 17 - this.name = 'ExternalSourceError'; 21 + this.name = "ExternalSourceError"; 18 22 Object.setPrototypeOf(this, ExternalSourceError.prototype); 19 23 } 20 24 } 21 25 22 - const loadDomainsFromExternalSource = async ({github, url}: LoadFromSource) => { 23 - if (cachedDomains) return cachedDomains; 24 - const URL = github ? "https://raw.githubusercontent.com/IntegerAlex/disposable-email-detector/refs/heads/main/index.json" : url; 25 - if (!URL) throw new ExternalSourceError(); 26 - try { 27 - const response = await fetch(URL); 28 - const disposableDomains = await response.json(); 29 - cachedDomains = disposableDomains 30 - return disposableDomains; 31 - } catch (error) { 32 - throw new ExternalSourceError("Failed to load disposable domains from the provided URL"); 33 - } 34 - } 26 + const loadDomainsFromExternalSource = async ({ 27 + github, 28 + url, 29 + }: LoadFromSource) => { 30 + if (cachedDomains) return cachedDomains; 31 + const URL = github 32 + ? "https://raw.githubusercontent.com/IntegerAlex/disposable-email-detector/refs/heads/main/index.json" 33 + : url; 34 + if (!URL) throw new ExternalSourceError(); 35 + try { 36 + const response = await fetch(URL); 37 + const disposableDomains = await response.json(); 38 + cachedDomains = disposableDomains; 39 + return disposableDomains; 40 + } catch (error) { 41 + throw new ExternalSourceError( 42 + "Failed to load disposable domains from the provided URL" 43 + ); 44 + } 45 + }; 35 46 36 47 type LoadFromSource = { 37 - github?: boolean; 38 - url?: string; 39 - } 48 + github?: boolean; 49 + url?: string; 50 + }; 40 51 41 52 type Options = { 42 - loadFromSource?: LoadFromSource; 43 - } 53 + loadFromSource?: LoadFromSource; 54 + }; 44 55 45 56 // Function to detect disposable email addresses 46 - export default async function disposableEmailDetector(email: string, options?: Options): Promise<boolean> { 57 + export default async function disposableEmailDetector( 58 + email: string, 59 + options?: Options 60 + ): Promise<boolean> { 47 61 try { 48 - let disposableDomains = []; 62 + let disposableDomains: string[] = []; 49 63 // Load from external source 50 64 if (options?.loadFromSource) { 51 - disposableDomains = await loadDomainsFromExternalSource(options.loadFromSource); 65 + disposableDomains = await loadDomainsFromExternalSource( 66 + options.loadFromSource 67 + ); 52 68 } else { 53 - disposableDomains = await loadDomains(); 69 + disposableDomains = await loadDomains(); 54 70 } 55 - 56 - 71 + 57 72 // Extract the domain from the email address 58 - const domain = email.split('@')[1].toLowerCase(); // Get the domain part of the email address and convert it to lowercase 73 + const domain = email.split("@")[1].toLowerCase(); // Get the domain part of the email address and convert it to lowercase 59 74 60 - // Check if the domain is in the list of disposable domains 75 + // Check if the domain is in the list of disposable domains 61 76 return disposableDomains.includes(domain); 62 - 63 77 } catch (error: any) { 64 - if (error.code === 'ENOENT') { 65 - console.error('index.json not found. Please create it with disposable domains.'); 78 + if (error.code === "ENOENT") { 79 + console.error( 80 + "index.json not found. Please create it with disposable domains." 81 + ); 66 82 } else if (error instanceof SyntaxError) { 67 - console.error('Invalid JSON format in index.json. Please correct the file.'); 83 + console.error( 84 + "Invalid JSON format in index.json. Please correct the file." 85 + ); 68 86 } else if (error instanceof ExternalSourceError) { 69 - console.error(error.message); 70 - } 71 - else { 72 - console.error('Unexpected error:', error); 87 + console.error(error.message); 88 + } else { 89 + console.error("Unexpected error:", error); 73 90 } 74 - return false; 91 + return false; 75 92 } 76 93 } 77 -
+105
package-lock.json
··· 1 + { 2 + "name": "disposable-email-detector", 3 + "version": "3.0.0", 4 + "lockfileVersion": 2, 5 + "requires": true, 6 + "packages": { 7 + "": { 8 + "name": "disposable-email-detector", 9 + "version": "3.0.0", 10 + "license": "MIT", 11 + "dependencies": { 12 + "disposable-email-detector": "^3.0.0" 13 + }, 14 + "devDependencies": { 15 + "@types/node": "^20.11.25", 16 + "typescript": "^5.4.2" 17 + } 18 + }, 19 + "node_modules/@types/node": { 20 + "version": "20.17.23", 21 + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.17.23.tgz", 22 + "integrity": "sha512-8PCGZ1ZJbEZuYNTMqywO+Sj4vSKjSjT6Ua+6RFOYlEvIvKQABPtrNkoVSLSKDb4obYcMhspVKmsw8Cm10NFRUg==", 23 + "dev": true, 24 + "dependencies": { 25 + "undici-types": "~6.19.2" 26 + } 27 + }, 28 + "node_modules/disposable-email-detector": { 29 + "version": "3.0.0", 30 + "resolved": "https://registry.npmjs.org/disposable-email-detector/-/disposable-email-detector-3.0.0.tgz", 31 + "integrity": "sha512-q/7bq+vXAupa8Z9eGlrpJ8qJ0Q3j8cgs15qvvdJNVnmFso8ludFFBVXoj4ALRfy66K92T9xdyWxl98RX9jlAiw==", 32 + "dependencies": { 33 + "disposable-email-detector": "^1.0.1" 34 + } 35 + }, 36 + "node_modules/disposable-email-detector/node_modules/disposable-email-detector": { 37 + "version": "1.0.3", 38 + "resolved": "https://registry.npmjs.org/disposable-email-detector/-/disposable-email-detector-1.0.3.tgz", 39 + "integrity": "sha512-hqVTnwz4B8iuFefKcp6I3m8J/ZXiNzBZROD2t3lS2cZlo+/hkKrsMvn9i9wyuXTGZ0WUblC8h/gSzybF9nVWiQ==", 40 + "dependencies": { 41 + "disposable-email-detector": "^1.0.1" 42 + } 43 + }, 44 + "node_modules/typescript": { 45 + "version": "5.8.2", 46 + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.8.2.tgz", 47 + "integrity": "sha512-aJn6wq13/afZp/jT9QZmwEjDqqvSGp1VT5GVg+f/t6/oVyrgXM6BY1h9BRh/O5p3PlUPAe+WuiEZOmb/49RqoQ==", 48 + "dev": true, 49 + "bin": { 50 + "tsc": "bin/tsc", 51 + "tsserver": "bin/tsserver" 52 + }, 53 + "engines": { 54 + "node": ">=14.17" 55 + } 56 + }, 57 + "node_modules/undici-types": { 58 + "version": "6.19.8", 59 + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz", 60 + "integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==", 61 + "dev": true 62 + } 63 + }, 64 + "dependencies": { 65 + "@types/node": { 66 + "version": "20.17.23", 67 + "resolved": "https://registry.npmjs.org/@types/node/-/node-20.17.23.tgz", 68 + "integrity": "sha512-8PCGZ1ZJbEZuYNTMqywO+Sj4vSKjSjT6Ua+6RFOYlEvIvKQABPtrNkoVSLSKDb4obYcMhspVKmsw8Cm10NFRUg==", 69 + "dev": true, 70 + "requires": { 71 + "undici-types": "~6.19.2" 72 + } 73 + }, 74 + "disposable-email-detector": { 75 + "version": "3.0.0", 76 + "resolved": "https://registry.npmjs.org/disposable-email-detector/-/disposable-email-detector-3.0.0.tgz", 77 + "integrity": "sha512-q/7bq+vXAupa8Z9eGlrpJ8qJ0Q3j8cgs15qvvdJNVnmFso8ludFFBVXoj4ALRfy66K92T9xdyWxl98RX9jlAiw==", 78 + "requires": { 79 + "disposable-email-detector": "^1.0.1" 80 + }, 81 + "dependencies": { 82 + "disposable-email-detector": { 83 + "version": "1.0.3", 84 + "resolved": "https://registry.npmjs.org/disposable-email-detector/-/disposable-email-detector-1.0.3.tgz", 85 + "integrity": "sha512-hqVTnwz4B8iuFefKcp6I3m8J/ZXiNzBZROD2t3lS2cZlo+/hkKrsMvn9i9wyuXTGZ0WUblC8h/gSzybF9nVWiQ==", 86 + "requires": { 87 + "disposable-email-detector": "^1.0.1" 88 + } 89 + } 90 + } 91 + }, 92 + "typescript": { 93 + "version": "5.8.2", 94 + "resolved": "https://registry.npmjs.org/typescript/-/typescript-5.8.2.tgz", 95 + "integrity": "sha512-aJn6wq13/afZp/jT9QZmwEjDqqvSGp1VT5GVg+f/t6/oVyrgXM6BY1h9BRh/O5p3PlUPAe+WuiEZOmb/49RqoQ==", 96 + "dev": true 97 + }, 98 + "undici-types": { 99 + "version": "6.19.8", 100 + "resolved": "https://registry.npmjs.org/undici-types/-/undici-types-6.19.8.tgz", 101 + "integrity": "sha512-ve2KP6f/JnbPBFyobGHuerC9g1FYGn/F8n1LWTwNxCEzd6IfqTwUQcNXgEtmmQ6DlRrC1hrSrBnCZPokRrDHjw==", 102 + "dev": true 103 + } 104 + } 105 + }