Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Cache the domains #3

Merged
merged 1 commit into from
Feb 17, 2025
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 12 additions & 3 deletions index.ts
Original file line number Diff line number Diff line change
@@ -1,12 +1,21 @@
import fs from 'fs/promises';
import Path from 'path';
import path from 'path';

let cachedDomains: string[] | undefined = undefined;

const loadDomains = async () => {
if(cachedDomains) return cachedDomains;
const disposableDomainsBuffer = await fs.readFile(path.join(__dirname, 'index.json'));
const disposableDomains = JSON.parse(disposableDomainsBuffer.toString());
cachedDomains = disposableDomains;

Check failure on line 10 in index.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

index.ts#L10

Unsafe assignment of an `any` value.
return disposableDomains;

Check failure on line 11 in index.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

index.ts#L11

Unsafe return of an `any` typed value.
}

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

Check failure on line 18 in index.ts

View check run for this annotation

Codacy Production / Codacy Static Code Analysis

index.ts#L18

Unsafe assignment of an `any` value.

// 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
Expand Down