"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.cleanEmails = exports.checkAndCleanEmail = void 0;
const checkAndCleanEmail = (email) => {
    const expression = /^[a-zA-Z0-9.!#$%&'*+-=?^_`{|}~]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,9})$|^[\w\s]+<\s*[a-zA-Z0-9.!#$%&'*+-=?^_`{|}~]+@[a-zA-Z0-9-]+(\.[a-zA-Z0-9-]+)*(\.[a-zA-Z]{2,9})\s*>$/;
    const trimmedEmail = email.trim();
    if (!expression.test(trimmedEmail)) {
        throw new Error(`Invalid email format: ${trimmedEmail}`);
    }
    return trimmedEmail;
};
exports.checkAndCleanEmail = checkAndCleanEmail;
const cleanEmails = (emailsString) => {
    if (emailsString) {
        const emails = emailsString.split(',');
        if (typeof emails !== 'undefined' && Array.isArray(emails)) {
            return emails.filter(Boolean).map((email) => checkAndCleanEmail(email));
        }
    }
    return [];
};
exports.cleanEmails = cleanEmails;
//# sourceMappingURL=checkAndCleanEmail.js.map