-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrepository.js
More file actions
31 lines (26 loc) · 1.08 KB
/
Copy pathrepository.js
File metadata and controls
31 lines (26 loc) · 1.08 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
if (typeof LpseRepository === 'undefined') {
window.LpseRepository = class LpseRepository {
static toCSV(dataArray) {
if (dataArray.length === 0) return "";
// AMBIL SEMUA KOLOM SECARA DINAMIS DARI DATA PERTAMA
const columns = Object.keys(dataArray[0]);
// Header
const header = columns.map(col => col.replace(/_/g, ' ').toUpperCase()).join(";") + "\n";
// Body
const body = dataArray.map(item => {
return columns.map(col => {
let val = item[col];
// Handle null/undefined
if (val === null || val === undefined) val = "";
// Handle string yang butuh escape
if (typeof val === 'string') val = val.replace(/"/g, '""');
return `"${val}"`;
}).join(";");
}).join("\n");
return header + body;
}
static toJSON(dataArray) {
return JSON.stringify(dataArray, null, 4);
}
}
}