Skip to content
Draft
Show file tree
Hide file tree
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
5 changes: 4 additions & 1 deletion index.js
Original file line number Diff line number Diff line change
Expand Up @@ -63,7 +63,10 @@ function disposableEmailDetector(email, options) {
disposableDomains = yield loadDomains();
}
// 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
const domainPart = email.split('@')[1];
if (!domainPart)
return false;
const domain = domainPart.toLowerCase(); // Get the domain part of the email address and convert it to lowercase
// Check if the domain is in the list of disposable domains
return disposableDomains.includes(domain);
}
Expand Down
5 changes: 3 additions & 2 deletions index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,9 @@ export default async function disposableEmailDetector(email: string, options?: O


// 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
const domainPart = email.split('@')[1];
if (!domainPart) return false;
const domain = domainPart.toLowerCase(); // Get the domain part of the email address and convert it to lowercase

// Check if the domain is in the list of disposable domains
return disposableDomains.includes(domain);
Expand All @@ -74,4 +76,3 @@ export default async function disposableEmailDetector(email: string, options?: O
return false;
}
}

13 changes: 10 additions & 3 deletions test/package.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,13 @@
import disposableEmailDetector from 'disposable-email-detector'
import disposableEmailDetector from '../index'
import assert from 'assert'

// Test the disposableEmailDetector function
(async () => {
console.log(await disposableEmailDetector('user69@spamavert.com')); // false
})();
assert.strictEqual(await disposableEmailDetector('user@mailinator.com'), true);
assert.strictEqual(await disposableEmailDetector('user1@gmail.com'), false);
assert.strictEqual(await disposableEmailDetector('invalid-email'), false);
assert.strictEqual(await disposableEmailDetector('@'), false);
assert.strictEqual(await disposableEmailDetector('user@@example.com'), false);
assert.strictEqual(await disposableEmailDetector(''), false);
console.log('test package passed');
})();