UNPKG

maileroo-sdk

Version:

Official Node.js SDK for Maileroo v2 API. Send transactional/marketing emails via Maileroo with a simple and intuitive API.

32 lines (31 loc) 989 B
const EMAIL_RE = /^[^\s@]+@[^\s@]+\.[^\s@]+$/; export class EmailAddress { constructor(address, displayName) { if (address.trim() === "") { throw new Error("Email address must be a non-empty string."); } if (!EMAIL_RE.test(address)) { throw new Error("Invalid email address format: " + address); } if (displayName !== undefined && displayName !== null) { if (displayName.trim() === "") { throw new Error("Display name must be a non-empty string or null."); } } this.address = address; this.displayName = displayName ?? null; } getAddress() { return this.address; } getDisplayName() { return this.displayName; } toJSON() { const data = { address: this.address }; if (this.displayName !== null) data.display_name = this.displayName; return data; } } export default EmailAddress;