"use strict";
Object.defineProperty(exports, "__esModule", { value: true });
exports.downloadCsvFile = void 0;
const file_saver_1 = require("file-saver");
const json2csv_1 = require("json2csv");
/**
 * Generates a CSV file from JSON data and triggers a download in the client
 *
 * @param data json2csv data, see https://www.npmjs.com/package/json2csv#javascript-module-examples
 * @param fileName name of the downloaded file
 * @param opts json2csv options, see https://www.npmjs.com/package/json2csv#available-options
 */
exports.downloadCsvFile = (data, fileName, opts) => {
    const csvOutput = json2csv_1.parse(data, opts);
    const blob = new Blob([csvOutput], { type: 'text/csv' });
    const formattedFilename = fileName.endsWith('.csv')
        ? fileName
        : `${fileName}.csv`;
    file_saver_1.saveAs(blob, formattedFilename);
};
//# sourceMappingURL=downloadCsvFile.js.map