@papb/json-excel
Version:
Create a pretty Excel table from JSON data with a very simple API
27 lines • 1.36 kB
JavaScript
;
var __importDefault = (this && this.__importDefault) || function (mod) {
return (mod && mod.__esModule) ? mod : { "default": mod };
};
Object.defineProperty(exports, "__esModule", { value: true });
exports.exportJsonToExcelNodejs = void 0;
const fs_jetpack_1 = __importDefault(require("fs-jetpack"));
const json_to_excel_1 = require("./json-to-excel");
const defaults_1 = require("./defaults");
async function exportJsonToExcelNodejs(destinationPath, sheets, options) {
const expandedOptions = defaults_1.expandExportJsonToExcelOptions(options);
const existence = fs_jetpack_1.default.exists(destinationPath);
if (existence === 'dir') {
throw new Error(`Destination path is a directory: "${destinationPath}"`);
}
if (existence === 'other') {
throw new Error(`Destination path already exists and is not a file: "${destinationPath}"`);
}
if (existence === 'file' && !expandedOptions.overwrite) {
throw new Error(`Destination file already exists, refusing to overwrite: "${destinationPath}"`);
}
const workbook = json_to_excel_1.jsonToExcel(sheets, expandedOptions);
await expandedOptions.beforeSave(workbook);
await workbook.xlsx.writeFile(destinationPath);
}
exports.exportJsonToExcelNodejs = exportJsonToExcelNodejs;
//# sourceMappingURL=export-json-to-excel-nodejs.js.map