From def29705c62c01dedd1b3b6595961c3645010258 Mon Sep 17 00:00:00 2001 From: matt Date: Mon, 14 Feb 2022 17:05:44 +0000 Subject: [PATCH] Added documentation for EmailBuilder class --- lib/Emailer.js | 95 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 95 insertions(+) diff --git a/lib/Emailer.js b/lib/Emailer.js index 97cd9b2..82e8744 100644 --- a/lib/Emailer.js +++ b/lib/Emailer.js @@ -1,16 +1,61 @@ 'use strict'; +/** + * removeDupes() Removes item from src array that appear in dest + * + * @param {Array} src - The source array to remove duplicates from + * @param {Array} dest - The array to check against + * + * @return {Array} - The filtered array + */ function removeDupes(src, dest) { return src.filter(item => !dest.includes(item)); } +/** + * A class to allow for easy construction of emails + */ class EmailBuilder { + /** + * The subject of the email + * @type {string} + */ subject; + + /** + * The plaintext body of the email + * @type {string} + */ body; + + /** + * The html body of the email + * @type {string} + */ HTMLBody; + + /** + * The from address for the email + * @type {string} + */ from = 'Stratos '; + + /** + * The addresses to send to + * @type {Array} + */ to; + + /** + * The addresses to carbon copy to + * @type {Array} + */ cc; + + /** + * The addresses to blind carbon copy to + * @type {Array} + */ bcc; constructor() { @@ -19,54 +64,104 @@ class EmailBuilder { this.bcc = []; } + /** + * Sets the subject of the email + * @param {string} subject - The subject to set + * @returns {EmailBuilder} + */ setSubject(subject) { this.subject = subject; return this; } + /** + * Sets the plaintext body of the email + * @param {string} body - The body to set + * @returns {EmailBuilder} + */ setBody(body) { this.body = body; return this; } + /** + * Sets the HTML body of the email + * @param {string} HTMLBody - The body to set + * @returns {EmailBuilder} + */ setHTMLBody(HTMLBody) { this.HTMLBody = HTMLBody; return this; } + /** + * Sets the from address of the email + * @param {string} from - The address to set + * @returns {EmailBuilder} + */ setFrom(from) { this.from = from; return this; } + /** + * Adds a list of addresses to the 'to' addresses + * @param {Array} addresses - The addresses to add + * @returns {EmailBuilder} + */ addTo(addresses) { const newAddresses = removeDupes(addresses, this.to); this.to.push(...newAddresses); return this; } + /** + * Removes a list of addresses from the 'to' addresses + * @param {Array} addresses - The addresses to remove + * @returns {EmailBuilder} + */ removeTo(addresses) { this.to = removeDupes(this.to, addresses); return this; } + /** + * Adds a list of addresses to the 'cc' addresses + * @param {Array} addresses - The addresses to add + * @returns {EmailBuilder} + */ addCC(addresses) { const newAddresses = removeDupes(addresses, this.to); this.cc.push(...newAddresses); return this; } + /** + * Removes a list of addresses from the 'cc' addresses + * @param {Array} addresses - The addresses to remove + * @returns {EmailBuilder} + */ removeCC(addresses) { this.cc = removeDupes(this.cc, addresses); return this; } + /** + * Adds a list of addresses to the 'bcc' addresses + * @param {Array} addresses - The addresses to add + * @returns {EmailBuilder} + */ addBCC(addresses) { const newAddresses = removeDupes(addresses, this.to); this.bcc.push(...newAddresses); return this; } + /** + * Removes a list of addresses from the 'bcc' addresses + * @param {Array} addresses - The addresses to remove + * @returns {EmailBuilder} + */ removeBCC(addresses) { this.bcc = removeDupes(this.bcc, addresses); return this;