22 lines
820 B
JavaScript
22 lines
820 B
JavaScript
import fs from 'node:fs';
|
|
|
|
const inPath = 'data/guests.csv';
|
|
const outPath = 'data/guest-links.csv';
|
|
const rows = fs.readFileSync(inPath, 'utf8').trim().split(/\r?\n/);
|
|
|
|
const [header, ...lines] = rows;
|
|
const cols = header.split(',');
|
|
const codeIdx = cols.indexOf('inviteCode');
|
|
const nameIdx = cols.indexOf('name');
|
|
|
|
const out = ['inviteCode,name,url'];
|
|
for (const line of lines) {
|
|
// very light CSV parse for two fields; adjust if you expect embedded commas
|
|
const parts = line.split(',');
|
|
const code = (parts[codeIdx] || '').trim().toUpperCase();
|
|
const name = (parts[nameIdx] || '').trim();
|
|
const url = `https://www.themoyos.co.za/invite?${encodeURIComponent(code)}`;
|
|
out.push(`${code},"${name.replace(/"/g,'""')}",${url}`);
|
|
}
|
|
fs.writeFileSync(outPath, out.join('\n'));
|
|
console.log(`✅ wrote ${outPath}`); |