feat: add JSON and CSV export
Co-Authored-By: Claude Sonnet 5.5 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Sonnet 5.5
parent
10f5c095b2
commit
1d03ee4054
@@ -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';
|
||||
}
|
||||
Reference in New Issue
Block a user