"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.toCsv = exports.escapeCsvCell = void 0;
const escapeCsvCell = (value) => {
    const s = value == null ? '' : String(value);
    // RFC 4180-ish: quote if contains comma, quote, or newline
    if (/[",\r\n]/.test(s)) {
        return `"${s.replace(/"/g, '""')}"`;
    }
    return s;
};
exports.escapeCsvCell = escapeCsvCell;
const toCsv = (headers, rows) => {
    const lines = [];
    lines.push(headers.map(exports.escapeCsvCell).join(','));
    for (const row of rows) {
        lines.push(headers.map((h) => (0, exports.escapeCsvCell)(row[h])).join(','));
    }
    return lines.join('\n');
};
exports.toCsv = toCsv;
//# sourceMappingURL=csvUtils.js.map