@papb/json-excel
Version:
Create a pretty Excel table from JSON data with a very simple API
53 lines • 3.02 kB
JavaScript
"use strict";
/* Ensure this file is consistent with ./types.ts */
Object.defineProperty(exports, "__esModule", { value: true });
exports.expandExportJsonToExcelOptions = exports.expandJsonToExcelOptions = exports.expandJsonSheet = exports.expandAutoFitCellSizesOptions = void 0;
function expandAutoFitCellSizesOptions(options) {
var _a, _b, _c, _d, _e, _f;
if (options.maxHeight && options.maxHeight > 408) {
throw new Error(`autoFitCellSizesOptions.maxHeight cannot be greater than 408, got ${options.maxHeight}`);
}
if (options.maxWidth && options.maxWidth > 254) {
throw new Error(`autoFitCellSizesOptions.maxWidth cannot be greater than 254, got ${options.maxWidth}`);
}
return {
minHeight: (_a = options.minHeight) !== null && _a !== void 0 ? _a : 15,
maxHeight: (_b = options.maxHeight) !== null && _b !== void 0 ? _b : 408,
minWidth: (_c = options.minWidth) !== null && _c !== void 0 ? _c : 6,
maxWidth: (_d = options.maxWidth) !== null && _d !== void 0 ? _d : 170,
horizontalPadding: (_e = options.horizontalPadding) !== null && _e !== void 0 ? _e : 3,
verticalPadding: (_f = options.verticalPadding) !== null && _f !== void 0 ? _f : 2
};
}
exports.expandAutoFitCellSizesOptions = expandAutoFitCellSizesOptions;
function expandJsonSheet(sheet) {
var _a, _b, _c, _d, _e;
return {
sheetName: sheet.sheetName.replace(/\r?\n/g, '\n'),
data: sheet.data,
formatAsTable: (_a = sheet.formatAsTable) !== null && _a !== void 0 ? _a : false,
tableTheme: (_b = sheet.tableTheme) !== null && _b !== void 0 ? _b : 'TableStyleMedium9',
autoTrimWhitespace: (_c = sheet.autoTrimWhitespace) !== null && _c !== void 0 ? _c : true,
autoFitCellSizes: (_d = sheet.autoFitCellSizes) !== null && _d !== void 0 ? _d : true,
autoFitCellSizesOptions: expandAutoFitCellSizesOptions((_e = sheet.autoFitCellSizesOptions) !== null && _e !== void 0 ? _e : {})
};
}
exports.expandJsonSheet = expandJsonSheet;
function expandJsonToExcelOptions(options) {
var _a, _b;
return {
normalizeLinefeeds: (_a = options === null || options === void 0 ? void 0 : options.normalizeLinefeeds) !== null && _a !== void 0 ? _a : true,
linefeedLimitChecking: (_b = options === null || options === void 0 ? void 0 : options.linefeedLimitChecking) !== null && _b !== void 0 ? _b : 'legacy'
};
}
exports.expandJsonToExcelOptions = expandJsonToExcelOptions;
function expandExportJsonToExcelOptions(options) {
var _a, _b;
return {
...expandJsonToExcelOptions(options),
overwrite: (_a = options === null || options === void 0 ? void 0 : options.overwrite) !== null && _a !== void 0 ? _a : false,
beforeSave: (_b = options === null || options === void 0 ? void 0 : options.beforeSave) !== null && _b !== void 0 ? _b : (() => { })
};
}
exports.expandExportJsonToExcelOptions = expandExportJsonToExcelOptions;
//# sourceMappingURL=defaults.js.map