@email-service/email-service
Version:
email-service is a versatile npm package designed to simplify the integration and standardization of email communications across multiple Email Service Providers (ESPs).
39 lines (38 loc) • 1.71 kB
TypeScript
import { FromInput, Recipient, RecipientInput } from "../types/email.type";
/**
* Normalizes various email recipient inputs into an array of `{ name, email }` objects.
*
* @param to - Can be:
* - A string containing a single email address (`"john@example.com"`)
* - A string containing multiple emails separated by commas (`"john@example.com, jane@example.com"`)
* - A string in the format "Name <email>" (`"John Doe <john@example.com>"`)
* - An array of strings mixing these formats
* - An object `{ name: string, email: string }`
* - An array of objects `{ name: string, email: string }` or a mix of objects and strings
*
* @returns An array of normalized `{ name, email }` objects.
*/
export declare function normalizeRecipients(to: RecipientInput): Recipient[];
/**
* Normalizes various email from inputs into an object `{ name, email }`.
*
* @param to - Can be:
* - A string containing a single email address (`"john@example.com"`)
* - A string in the format "Name <email>" (`"John Doe <john@example.com>"`)
* - An object `{ name: string, email: string }`
*
* @returns An array of normalized `{ name, email }` objects.
*/
export declare function normalizeFrom(from: FromInput): Recipient | undefined;
/**
* Checks if an email address is valid
* @param email The email address to validate
* @returns true if the email is valid, false otherwise
*/
export declare const isValidEmail: (email: string) => boolean;
/**
* Filters out recipients with invalid email addresses
* @param recipients List of recipients
* @returns List of recipients with invalid email addresses
*/
export declare const checkValidityOfEmails: (recipients: Recipient[]) => Recipient[];