1 import cloneDeep from 'lodash.clonedeep';
2 import calculateMaximumColumnWidthIndex from './calculateMaximumColumnWidthIndex';
3 import getBorderCharacters from './getBorderCharacters';
4 import validateConfig from './validateConfig';
7 * Merges user provided border characters with the default border ("honeywell") characters.
9 * @param {object} border
12 const makeBorder = (border = {}) => {
13 return Object.assign({}, getBorderCharacters('honeywell'), border);
17 * Creates a configuration for every column using default
18 * values for the missing configuration properties.
20 * @param {Array[]} rows
21 * @param {object} columns
22 * @param {object} columnDefault
25 const makeColumns = (rows, columns = {}, columnDefault = {}) => {
26 const maximumColumnWidthIndex = calculateMaximumColumnWidthIndex(rows);
28 for (let index = 0; index < rows[0].length; index++) {
29 if (typeof columns[index] === 'undefined') {
33 columns[index] = Object.assign({
37 truncate: Number.POSITIVE_INFINITY,
38 width: maximumColumnWidthIndex[index],
40 }, columnDefault, columns[index]);
47 * Makes a new configuration object out of the userConfig object
48 * using default values for the missing configuration properties.
50 * @param {Array[]} rows
51 * @param {object} userConfig
54 export default (rows, userConfig = {}) => {
55 validateConfig('config.json', userConfig);
57 const config = cloneDeep(userConfig);
59 config.border = makeBorder(config.border);
60 config.columns = makeColumns(rows, config.columns, config.columnDefault);
62 if (!config.drawHorizontalLine) {
66 config.drawHorizontalLine = () => {
71 if (config.singleLine === undefined) {
72 config.singleLine = false;