2020-08-26 01:57:08 +02:00
|
|
|
"use strict";
|
|
|
|
|
|
|
|
Object.defineProperty(exports, "__esModule", {
|
|
|
|
value: true
|
|
|
|
});
|
|
|
|
exports.default = void 0;
|
|
|
|
|
|
|
|
var _cloneDeep2 = _interopRequireDefault(require("lodash/cloneDeep"));
|
|
|
|
|
|
|
|
var _isUndefined2 = _interopRequireDefault(require("lodash/isUndefined"));
|
|
|
|
|
|
|
|
var _times2 = _interopRequireDefault(require("lodash/times"));
|
|
|
|
|
|
|
|
var _getBorderCharacters = _interopRequireDefault(require("./getBorderCharacters"));
|
|
|
|
|
|
|
|
var _validateConfig = _interopRequireDefault(require("./validateConfig"));
|
|
|
|
|
|
|
|
function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Merges user provided border characters with the default border ("honeywell") characters.
|
|
|
|
*
|
2021-02-26 04:58:33 +01:00
|
|
|
* @param {object} border
|
|
|
|
* @returns {object}
|
2020-08-26 01:57:08 +02:00
|
|
|
*/
|
|
|
|
const makeBorder = (border = {}) => {
|
|
|
|
return Object.assign({}, (0, _getBorderCharacters.default)('honeywell'), border);
|
|
|
|
};
|
|
|
|
/**
|
|
|
|
* Creates a configuration for every column using default
|
|
|
|
* values for the missing configuration properties.
|
|
|
|
*
|
|
|
|
* @param {number} columnCount
|
2021-02-26 04:58:33 +01:00
|
|
|
* @param {object} columns
|
|
|
|
* @param {object} columnDefault
|
|
|
|
* @returns {object}
|
2020-08-26 01:57:08 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
const makeColumns = (columnCount, columns = {}, columnDefault = {}) => {
|
|
|
|
(0, _times2.default)(columnCount, index => {
|
|
|
|
if ((0, _isUndefined2.default)(columns[index])) {
|
|
|
|
columns[index] = {};
|
|
|
|
}
|
|
|
|
|
|
|
|
columns[index] = Object.assign({
|
|
|
|
alignment: 'left',
|
|
|
|
paddingLeft: 1,
|
|
|
|
paddingRight: 1,
|
2021-02-26 04:58:33 +01:00
|
|
|
truncate: Number.POSITIVE_INFINITY,
|
2020-08-26 01:57:08 +02:00
|
|
|
wrapWord: false
|
|
|
|
}, columnDefault, columns[index]);
|
|
|
|
});
|
|
|
|
return columns;
|
|
|
|
};
|
|
|
|
/**
|
2021-02-26 04:58:33 +01:00
|
|
|
* @typedef {object} columnConfig
|
2020-08-26 01:57:08 +02:00
|
|
|
* @property {string} alignment
|
|
|
|
* @property {number} width
|
|
|
|
* @property {number} truncate
|
|
|
|
* @property {number} paddingLeft
|
|
|
|
* @property {number} paddingRight
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
2021-02-26 04:58:33 +01:00
|
|
|
* @typedef {object} streamConfig
|
2020-08-26 01:57:08 +02:00
|
|
|
* @property {columnConfig} columnDefault
|
2021-02-26 04:58:33 +01:00
|
|
|
* @property {object} border
|
2020-08-26 01:57:08 +02:00
|
|
|
* @property {columnConfig[]}
|
|
|
|
* @property {number} columnCount Number of columns in the table (required).
|
|
|
|
*/
|
|
|
|
|
|
|
|
/**
|
|
|
|
* Makes a new configuration object out of the userConfig object
|
|
|
|
* using default values for the missing configuration properties.
|
|
|
|
*
|
|
|
|
* @param {streamConfig} userConfig
|
2021-02-26 04:58:33 +01:00
|
|
|
* @returns {object}
|
2020-08-26 01:57:08 +02:00
|
|
|
*/
|
|
|
|
|
|
|
|
|
|
|
|
const makeStreamConfig = (userConfig = {}) => {
|
|
|
|
(0, _validateConfig.default)('streamConfig.json', userConfig);
|
|
|
|
const config = (0, _cloneDeep2.default)(userConfig);
|
|
|
|
|
|
|
|
if (!config.columnDefault || !config.columnDefault.width) {
|
|
|
|
throw new Error('Must provide config.columnDefault.width when creating a stream.');
|
|
|
|
}
|
|
|
|
|
|
|
|
if (!config.columnCount) {
|
|
|
|
throw new Error('Must provide config.columnCount.');
|
|
|
|
}
|
|
|
|
|
|
|
|
config.border = makeBorder(config.border);
|
|
|
|
config.columns = makeColumns(config.columnCount, config.columns, config.columnDefault);
|
|
|
|
return config;
|
|
|
|
};
|
|
|
|
|
|
|
|
var _default = makeStreamConfig;
|
|
|
|
exports.default = _default;
|
|
|
|
//# sourceMappingURL=makeStreamConfig.js.map
|