I've created a node.js website that potential employees can apply for a job through. When they submit the application form I am using nodemailer and mailgun to send an email to the hiring manager with the applicants information. It sends the object of the new applicant with the key value pairs, but I would like to put a space between the keys containing more than one word and make them uppercase to be a little more eye pleasing. How can I do this?
here is a sample email with output key value pairs
Here is the code for sending an email
function sendAppliedEmail(applicant) {
let html = '<img src="" alt="logo">';
html += '<h2 style="color: black">New Applicant</h2>'
html += '<ul>';
Object.entries(applicant).forEach(([key, value]) => {
html += `<li>${key}: ${value}</li>`;
});
html += '</ul>';
replace(/([a-z])([A-Z])/g, `$1 $2`)
You can replace all lowerUpper matches.
Everytime a lowercase character followed by a uppercase character, the regex match and replace the both characters with themself and a space between.
function sendAppliedEmail(applicant) {
let html = '<img src="" alt="logo">';
html += '<h2 style="color: black">New Applicant</h2>'
html += '<ul>';
Object.entries(applicant).forEach(([key, value]) => {
html += `<li>${key.replace(/([a-z])([A-Z])/g, `$1 $2`)}: ${value}</li>`;
});
html += '</ul>';
if the key should be complete uppercase you can chain the toUpperCase()
method to the replace method.
html += `<li>${key.replace(/([a-z])([A-Z])/g, `$1 $2`).toUpperCase()}: ${value}</li>`;
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With