-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindex.js
More file actions
45 lines (41 loc) · 1.21 KB
/
index.js
File metadata and controls
45 lines (41 loc) · 1.21 KB
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
/**
* LoanBoard
* Simple HTML dashboard generator for loan management
*/
function escapeHtml(str){
if (str === null || str === undefined) return '';
return String(str)
.replace(/&/g,'&')
.replace(/</g,'<')
.replace(/>/g,'>')
.replace(/"/g,'"')
.replace(/'/g,''');
}
function renderLoanBoard(loans = [], opts = {}) {
const title = escapeHtml(opts.title || 'LoanBoard');
const columns = opts.columns || ['id','borrower','amount','status','dueDate'];
const rows = (loans || []).map(loan => {
return `<tr>` + columns.map(col => `<td>${escapeHtml(loan[col] ?? '')}</td>`).join('') + `</tr>`;
}).join('\n');
return `<!doctype html>` +
`<html>` +
`<head>` +
`<meta charset="utf-8"/>` +
`<meta name="viewport" content="width=device-width,initial-scale=1"/>` +
`<title>${title}</title>` +
`<link rel="stylesheet" href="./styles.css">` +
`</head>` +
`<body>` +
`<div class="loanboard">` +
`<h1>${title}</h1>` +
`<div class="table-wrap">` +
`<table class="loan-table">` +
`<thead><tr>` + columns.map(c=>`<th>${escapeHtml(c)}</th>`).join('') + `</tr></thead>` +
`<tbody>${rows}</tbody>` +
`</table>` +
`</div>` +
`</div>` +
`</body>` +
`</html>`;
}
module.exports = { renderLoanBoard };