feat: add JSON and CSV export

Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
IgorVolochay
2026-10-25 10:49:23 +03:00
co-authored by Claude Sonnet 5.5
parent 10f5c095b2
commit 1d03ee4054
2 changed files with 95 additions and 0 deletions
+34
View File
@@ -0,0 +1,34 @@
export const COLUMNS = [
'videoId',
'title',
'url',
'thumbnailUrl',
'channelId',
'channelTitle',
'channelUrl',
'subscribers',
'views',
'publishedAt',
'durationSec',
'isShort',
'score',
'vidiqScore',
'foundOn',
'firstSeenAt',
'updatedAt',
];
export function toJson(records) {
return JSON.stringify(records, null, 2);
}
function csvCell(value) {
if (value === null || value === undefined) return '';
const text = String(value);
return /[",\r\n]/.test(text) ? `"${text.replaceAll('"', '""')}"` : text;
}
export function toCsv(records) {
const lines = [COLUMNS.join(','), ...records.map((r) => COLUMNS.map((c) => csvCell(r[c])).join(','))];
return lines.join('\r\n') + '\r\n';
}