@oclif/core 1.9.2 → 1.9.3

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 CHANGED
@@ -2,6 +2,8 @@
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.3](https://github.com/oclif/core/compare/v1.9.2...v1.9.3) (2022-06-16)
6
+
5
7
  ### [1.9.2](https://github.com/oclif/core/compare/v1.9.1...v1.9.2) (2022-06-14)
6
8
 
7
9
  ### [1.9.1](https://github.com/oclif/core/compare/v1.9.0...v1.9.1) (2022-06-14)
@@ -11,14 +11,16 @@ 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 || false;
19
- const get = col.get || ((row) => row[key]);
20
+ const extended = (_a = col.extended) !== null && _a !== void 0 ? _a : false;
21
+ const get = (_b = col.get) !== null && _b !== void 0 ? _b : ((row) => row[key]);
20
22
  const header = typeof col.header === 'string' ? col.header : (0, util_1.capitalize)(key.replace(/_/g, ' '));
21
- const minWidth = Math.max(col.minWidth || 0, sw(header) + 1);
23
+ const minWidth = Math.max((_c = col.minWidth) !== null && _c !== void 0 ? _c : 0, sw(header) + 1);
22
24
  return {
23
25
  extended,
24
26
  get,
@@ -34,9 +36,9 @@ class Table {
34
36
  output: csv ? 'csv' : output,
35
37
  extended,
36
38
  filter,
37
- 'no-header': options['no-header'] || false,
38
- 'no-truncate': options['no-truncate'] || false,
39
- printLine: printLine || ((s) => process.stdout.write(s + '\n')),
39
+ 'no-header': (_a = options['no-header']) !== null && _a !== void 0 ? _a : false,
40
+ 'no-truncate': (_b = options['no-truncate']) !== null && _b !== void 0 ? _b : false,
41
+ printLine: printLine !== null && printLine !== void 0 ? printLine : ((s) => process.stdout.write(s + '\n')),
40
42
  rowStart: ' ',
41
43
  sort,
42
44
  title,
@@ -130,9 +132,10 @@ class Table {
130
132
  return data.map((d) => {
131
133
  // eslint-disable-next-line unicorn/prefer-object-from-entries
132
134
  return columns.reduce((obj, col) => {
135
+ var _a;
133
136
  return {
134
137
  ...obj,
135
- [col.key]: d[col.key] || '',
138
+ [col.key]: (_a = d[col.key]) !== null && _a !== void 0 ? _a : '',
136
139
  };
137
140
  }, {});
138
141
  });
@@ -156,25 +159,18 @@ class Table {
156
159
  }
157
160
  outputTable() {
158
161
  // tslint:disable-next-line:no-this-assignment
159
- const { data, columns, options } = this;
162
+ const { data, options } = this;
160
163
  // column truncation
161
164
  //
162
165
  // find max width for each column
163
- for (const col of columns) {
164
- // convert multi-line cell to single longest line
165
- // for width calculations
166
- const widthData = data.map((row) => {
167
- const d = row[col.key];
168
- const manyLines = d.split('\n');
169
- if (manyLines.length > 1) {
170
- return '*'.repeat(Math.max(...manyLines.map((r) => sw(r))));
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
- }
166
+ const columns = this.columns.map(c => {
167
+ const maxWidth = Math.max(sw('.'.padEnd(c.minWidth - 1)), sw(c.header), getWidestColumnWith(data, c.key)) + 1;
168
+ return {
169
+ ...c,
170
+ maxWidth,
171
+ width: maxWidth,
172
+ };
173
+ });
178
174
  // terminal width
179
175
  const maxWidth = screen_1.stdtermwidth - 2;
180
176
  // truncation logic
@@ -310,3 +306,12 @@ exports.table = table;
310
306
  }
311
307
  table.flags = flags;
312
308
  })(table = exports.table || (exports.table = {}));
309
+ const getWidestColumnWith = (data, columnKey) => {
310
+ return data.reduce((previous, current) => {
311
+ const d = current[columnKey];
312
+ // convert multi-line cell to single longest line
313
+ // for width calculations
314
+ const manyLines = d.split('\n');
315
+ return Math.max(previous, manyLines.length > 1 ? Math.max(...manyLines.map((r) => sw(r))) : sw(d));
316
+ }, 0);
317
+ };
package/package.json CHANGED
@@ -1,7 +1,7 @@
1
1
  {
2
2
  "name": "@oclif/core",
3
3
  "description": "base library for oclif CLIs",
4
- "version": "1.9.2",
4
+ "version": "1.9.3",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/core/issues",
7
7
  "dependencies": {