Skip to content

Commit 72eb135

Browse files
committed
Add validation for filterEmails options
1 parent e3b9f13 commit 72eb135

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

index.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -290,6 +290,10 @@ class MiabClient {
290290
filterEmails(emails, options = {}) {
291291
let { regex = [], from = '', subject = '' } = options;
292292

293+
if (regex.length === 0 && from === '' && subject === '') {
294+
throw new Error('At least one option must be specified. All options cannot be default values.');
295+
}
296+
293297
if (!Array.isArray(regex)) {
294298
console.error('The regex option must be an array. Trying to experimentally convert it to an array.');
295299

@@ -302,14 +306,14 @@ class MiabClient {
302306

303307
return emails.filter(email => {
304308
// Check if the email matches the regex patterns.
305-
const regexMatch = regex.some(r => {
309+
const regexMatch = Array.isArray(regex) ? regex.some(r => {
306310
if (this.#isRegex(r)) {
307311
const regex = new RegExp(r);
308312
return regex.test(email.textAsHtml) || regex.test(email.text);
309313
} else {
310314
return email.textAsHtml.includes(r) || email.text.includes(r);
311315
}
312-
});
316+
}) : true;
313317

314318
// Check if the email is from the specified sender.
315319
const fromMatch = from ? email.from.text.includes(from) : true;

0 commit comments

Comments
 (0)