···2233[](https://codescene.io/projects/50926)
44
55-[](https://www.bestpractices.dev/projects/8456)
55+[](https://www.bestpractices.dev/projects/8638)
66
7788## Overview
···2222- Node.js
2323- npm
24242525-### Installation
2525+### Implementation Details
2626+2727+```javascript
2828+ npm i disposable-email-detector
2929+```
26302727-1. Clone the repository.
2828-2. Install dependencies:
3131+```javascript
3232+ import { disposableEmailDetector } from 'disposable-email-detector';
29333030- ```bash
3131- npm install
3434+ const email = 'test@mailinator.com';
32353333-### Implementation Details
3636+ disposableEmailDetector(email)
3737+ .then((response) => console.log(response)); // true
3838+```
34393540The disposableEmailDetector function reads a list of disposable email domains from index.json. It checks whether the provided email address belongs to a disposable domain and returns a boolean indicating the result.
36413742### Error Handling
38433939-If index.json is not found, the script informs you to create it with disposable domains.
4040-If index.json has an invalid JSON format, it prompts you to correct the file.
4141-Unexpected errors are logged to the console.
4444+- If `index.json` is not found, the script informs you to create it with disposable domains.
4545+- If `index.json` has an invalid JSON format, it prompts you to correct the file.
4646+- Unexpected errors are logged to the console.
+6-4
index.ts
···11import fs from 'fs/promises';
22-import Path from 'path';
22+import Path from 'path';
33+44+// Function to detect disposable email addresses
35export default async function disposableEmailDetector(email: string): Promise<boolean> {
46 try {
57 // Load the list of disposable email domains from the index.json file
68 const disposableDomainsBuffer = await fs.readFile(Path.join(__dirname, 'index.json'));
79 const disposableDomains = JSON.parse(disposableDomainsBuffer.toString());
88-1010+911 // Extract the domain from the email address
1010- const domain = email.split('@')[1].toLowerCase();
1212+ const domain = email.split('@')[1].toLowerCase(); // Get the domain part of the email address and convert it to lowercase
11131212- // Check if the domain is in the list of disposable domains
1414+ // Check if the domain is in the list of disposable domains
1315 return disposableDomains.includes(domain);
14161517 } catch (error: any) {