@oclif/core 1.9.2 → 1.9.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +6 -0
- package/lib/cli-ux/styled/table.js +29 -23
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -2,6 +2,12 @@
|
|
|
2
2
|
|
|
3
3
|
All notable changes to this project will be documented in this file. See [standard-version](https://github.com/conventional-changelog/standard-version) for commit guidelines.
|
|
4
4
|
|
|
5
|
+
### [1.9.5](https://github.com/oclif/core/compare/v1.9.4...v1.9.5) (2022-06-23)
|
|
6
|
+
|
|
7
|
+
### [1.9.4](https://github.com/oclif/core/compare/v1.9.3...v1.9.4) (2022-06-23)
|
|
8
|
+
|
|
9
|
+
### [1.9.3](https://github.com/oclif/core/compare/v1.9.2...v1.9.3) (2022-06-16)
|
|
10
|
+
|
|
5
11
|
### [1.9.2](https://github.com/oclif/core/compare/v1.9.1...v1.9.2) (2022-06-14)
|
|
6
12
|
|
|
7
13
|
### [1.9.1](https://github.com/oclif/core/compare/v1.9.0...v1.9.1) (2022-06-14)
|
|
@@ -11,14 +11,17 @@ const sw = require('string-width');
|
|
|
11
11
|
const { orderBy } = require('natural-orderby');
|
|
12
12
|
class Table {
|
|
13
13
|
constructor(data, columns, options = {}) {
|
|
14
|
+
var _a, _b;
|
|
14
15
|
this.data = data;
|
|
15
16
|
// assign columns
|
|
16
17
|
this.columns = Object.keys(columns).map((key) => {
|
|
18
|
+
var _a, _b, _c;
|
|
17
19
|
const col = columns[key];
|
|
18
|
-
const extended = col.extended
|
|
19
|
-
|
|
20
|
+
const extended = (_a = col.extended) !== null && _a !== void 0 ? _a : false;
|
|
21
|
+
// turn null and undefined into empty strings by default
|
|
22
|
+
const get = (_b = col.get) !== null && _b !== void 0 ? _b : ((row) => { var _a; return (_a = row[key]) !== null && _a !== void 0 ? _a : ''; });
|
|
20
23
|
const header = typeof col.header === 'string' ? col.header : (0, util_1.capitalize)(key.replace(/_/g, ' '));
|
|
21
|
-
const minWidth = Math.max(col.minWidth
|
|
24
|
+
const minWidth = Math.max((_c = col.minWidth) !== null && _c !== void 0 ? _c : 0, sw(header) + 1);
|
|
22
25
|
return {
|
|
23
26
|
extended,
|
|
24
27
|
get,
|
|
@@ -34,9 +37,9 @@ class Table {
|
|
|
34
37
|
output: csv ? 'csv' : output,
|
|
35
38
|
extended,
|
|
36
39
|
filter,
|
|
37
|
-
'no-header': options['no-header']
|
|
38
|
-
'no-truncate': options['no-truncate']
|
|
39
|
-
printLine: printLine
|
|
40
|
+
'no-header': (_a = options['no-header']) !== null && _a !== void 0 ? _a : false,
|
|
41
|
+
'no-truncate': (_b = options['no-truncate']) !== null && _b !== void 0 ? _b : false,
|
|
42
|
+
printLine: printLine !== null && printLine !== void 0 ? printLine : ((s) => process.stdout.write(s + '\n')),
|
|
40
43
|
rowStart: ' ',
|
|
41
44
|
sort,
|
|
42
45
|
title,
|
|
@@ -130,9 +133,10 @@ class Table {
|
|
|
130
133
|
return data.map((d) => {
|
|
131
134
|
// eslint-disable-next-line unicorn/prefer-object-from-entries
|
|
132
135
|
return columns.reduce((obj, col) => {
|
|
136
|
+
var _a;
|
|
133
137
|
return {
|
|
134
138
|
...obj,
|
|
135
|
-
[col.key]: d[col.key]
|
|
139
|
+
[col.key]: (_a = d[col.key]) !== null && _a !== void 0 ? _a : '',
|
|
136
140
|
};
|
|
137
141
|
}, {});
|
|
138
142
|
});
|
|
@@ -156,25 +160,18 @@ class Table {
|
|
|
156
160
|
}
|
|
157
161
|
outputTable() {
|
|
158
162
|
// tslint:disable-next-line:no-this-assignment
|
|
159
|
-
const { data,
|
|
163
|
+
const { data, options } = this;
|
|
160
164
|
// column truncation
|
|
161
165
|
//
|
|
162
166
|
// find max width for each column
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
}
|
|
172
|
-
return d;
|
|
173
|
-
});
|
|
174
|
-
const widths = ['.'.padEnd(col.minWidth - 1), col.header, ...widthData.map((row) => row)].map(r => sw(r));
|
|
175
|
-
col.maxWidth = Math.max(...widths) + 1;
|
|
176
|
-
col.width = col.maxWidth;
|
|
177
|
-
}
|
|
167
|
+
const columns = this.columns.map(c => {
|
|
168
|
+
const maxWidth = Math.max(sw('.'.padEnd(c.minWidth - 1)), sw(c.header), getWidestColumnWith(data, c.key)) + 1;
|
|
169
|
+
return {
|
|
170
|
+
...c,
|
|
171
|
+
maxWidth,
|
|
172
|
+
width: maxWidth,
|
|
173
|
+
};
|
|
174
|
+
});
|
|
178
175
|
// terminal width
|
|
179
176
|
const maxWidth = screen_1.stdtermwidth - 2;
|
|
180
177
|
// truncation logic
|
|
@@ -310,3 +307,12 @@ exports.table = table;
|
|
|
310
307
|
}
|
|
311
308
|
table.flags = flags;
|
|
312
309
|
})(table = exports.table || (exports.table = {}));
|
|
310
|
+
const getWidestColumnWith = (data, columnKey) => {
|
|
311
|
+
return data.reduce((previous, current) => {
|
|
312
|
+
const d = current[columnKey];
|
|
313
|
+
// convert multi-line cell to single longest line
|
|
314
|
+
// for width calculations
|
|
315
|
+
const manyLines = d.split('\n');
|
|
316
|
+
return Math.max(previous, manyLines.length > 1 ? Math.max(...manyLines.map((r) => sw(r))) : sw(d));
|
|
317
|
+
}, 0);
|
|
318
|
+
};
|