1 | "use strict";
|
2 |
|
3 | Object.defineProperty(exports, "__esModule", {
|
4 | value: true
|
5 | });
|
6 | exports.default = void 0;
|
7 |
|
8 | var _cloneDeep2 = _interopRequireDefault(require("lodash/cloneDeep"));
|
9 |
|
10 | var _isUndefined2 = _interopRequireDefault(require("lodash/isUndefined"));
|
11 |
|
12 | var _times2 = _interopRequireDefault(require("lodash/times"));
|
13 |
|
14 | var _getBorderCharacters = _interopRequireDefault(require("./getBorderCharacters"));
|
15 |
|
16 | var _validateConfig = _interopRequireDefault(require("./validateConfig"));
|
17 |
|
18 | function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | const makeBorder = (border = {}) => {
|
27 | return Object.assign({}, (0, _getBorderCharacters.default)('honeywell'), border);
|
28 | };
|
29 |
|
30 |
|
31 |
|
32 |
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 |
|
39 |
|
40 | const makeColumns = (columnCount, columns = {}, columnDefault = {}) => {
|
41 | (0, _times2.default)(columnCount, index => {
|
42 | if ((0, _isUndefined2.default)(columns[index])) {
|
43 | columns[index] = {};
|
44 | }
|
45 |
|
46 | columns[index] = Object.assign({
|
47 | alignment: 'left',
|
48 | paddingLeft: 1,
|
49 | paddingRight: 1,
|
50 | truncate: Infinity,
|
51 | wrapWord: false
|
52 | }, columnDefault, columns[index]);
|
53 | });
|
54 | return columns;
|
55 | };
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 |
|
65 |
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 |
|
74 |
|
75 |
|
76 |
|
77 |
|
78 |
|
79 |
|
80 |
|
81 |
|
82 | const makeStreamConfig = (userConfig = {}) => {
|
83 | (0, _validateConfig.default)('streamConfig.json', userConfig);
|
84 | const config = (0, _cloneDeep2.default)(userConfig);
|
85 |
|
86 | if (!config.columnDefault || !config.columnDefault.width) {
|
87 | throw new Error('Must provide config.columnDefault.width when creating a stream.');
|
88 | }
|
89 |
|
90 | if (!config.columnCount) {
|
91 | throw new Error('Must provide config.columnCount.');
|
92 | }
|
93 |
|
94 | config.border = makeBorder(config.border);
|
95 | config.columns = makeColumns(config.columnCount, config.columns, config.columnDefault);
|
96 | return config;
|
97 | };
|
98 |
|
99 | var _default = makeStreamConfig;
|
100 | exports.default = _default;
|
101 |
|
\ | No newline at end of file |