-
Notifications
You must be signed in to change notification settings - Fork 0
/
cover-letter.js
61 lines (52 loc) · 1.46 KB
/
cover-letter.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
const now = () => {
const d = new Date();
let month = '' + (d.getMonth() + 1);
let day = '' + d.getDate();
const year = d.getFullYear();
if (month.length < 2) {
month = '0' + month;
}
if (day.length < 2) {
day = '0' + day;
}
return [month, day, year].join('-');
};
const onLoad = () => {
// Closures:
// {string} template
// {object} data
const body = document.querySelector('body');
Object.keys(data).forEach(key => {
const re = new RegExp(`{{${key}}}`, 'g');
template = template.replace(re, data[key]);
});
// Date
template = template.replace(/\{\{date\}\}/gi, now());
// HR full name & title
if (data.companyPersonFullName && data.companyPersonTitle) {
template = template.replace(
/\{\{person\}\}/gi,
`
<h4>${data.companyPersonFullName}</h4>
<p class="break-after">${data.companyPersonTitle}</p>
`,
);
} else {
template = template.replace(/\{\{person\}\}/gi, '');
}
// HR first name
if (data.companyPersonFirstName) {
template = template.replace(
/\{\{salutation\}\}/gi,
`Dear ${data.companyPersonFirstName},`,
);
} else {
template = template.replace(
/\{\{salutation\}\}/gi,
`To Whom It May Concern,`,
);
}
// Final replacement
body.innerHTML = template;
};
window.addEventListener('load', onLoad);