massive update, probably broken
[dotfiles/.git] / .config / coc / extensions / node_modules / coc-prettier / node_modules / table / dist / src / makeTableConfig.js
1 "use strict";
2 var __importDefault = (this && this.__importDefault) || function (mod) {
3     return (mod && mod.__esModule) ? mod : { "default": mod };
4 };
5 Object.defineProperty(exports, "__esModule", { value: true });
6 exports.makeTableConfig = void 0;
7 const calculateColumnWidths_1 = __importDefault(require("./calculateColumnWidths"));
8 const utils_1 = require("./utils");
9 const validateConfig_1 = require("./validateConfig");
10 /**
11  * Creates a configuration for every column using default
12  * values for the missing configuration properties.
13  */
14 const makeColumnsConfig = (rows, columns, columnDefault) => {
15     const columnWidths = (0, calculateColumnWidths_1.default)(rows);
16     return rows[0].map((_, columnIndex) => {
17         return {
18             alignment: 'left',
19             paddingLeft: 1,
20             paddingRight: 1,
21             truncate: Number.POSITIVE_INFINITY,
22             verticalAlignment: 'top',
23             width: columnWidths[columnIndex],
24             wrapWord: false,
25             ...columnDefault,
26             ...columns === null || columns === void 0 ? void 0 : columns[columnIndex],
27         };
28     });
29 };
30 const makeHeaderConfig = (config) => {
31     if (!config.header) {
32         return undefined;
33     }
34     return {
35         alignment: 'center',
36         paddingLeft: 1,
37         paddingRight: 1,
38         truncate: Number.POSITIVE_INFINITY,
39         wrapWord: false,
40         ...config.header,
41     };
42 };
43 /**
44  * Makes a new configuration object out of the userConfig object
45  * using default values for the missing configuration properties.
46  */
47 const makeTableConfig = (rows, config = {}) => {
48     var _a, _b, _c;
49     (0, validateConfig_1.validateConfig)('config.json', config);
50     return {
51         ...config,
52         border: (0, utils_1.makeBorderConfig)(config.border),
53         columns: makeColumnsConfig(rows, config.columns, config.columnDefault),
54         drawHorizontalLine: (_a = config.drawHorizontalLine) !== null && _a !== void 0 ? _a : (() => {
55             return true;
56         }),
57         drawVerticalLine: (_b = config.drawVerticalLine) !== null && _b !== void 0 ? _b : (() => {
58             return true;
59         }),
60         header: makeHeaderConfig(config),
61         singleLine: (_c = config.singleLine) !== null && _c !== void 0 ? _c : false,
62     };
63 };
64 exports.makeTableConfig = makeTableConfig;
65 //# sourceMappingURL=makeTableConfig.js.map