@oclif/table 0.4.11 → 0.4.13
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/lib/table.d.ts +2 -1
- package/lib/table.js +9 -4
- package/lib/types.d.ts +11 -0
- package/package.json +6 -6
package/lib/table.d.ts
CHANGED
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { CellProps, ContainerProps, HorizontalAlignment, Overflow, TableOptions } from './types.js';
|
|
3
|
-
export declare function formatTextWithMargins({ horizontalAlignment, overflow, padding, value, width
|
|
3
|
+
export declare function formatTextWithMargins({ horizontalAlignment, overflow, padding, trimWhitespace, value, width }: {
|
|
4
4
|
overflow: Overflow;
|
|
5
5
|
value: unknown;
|
|
6
6
|
width: number;
|
|
7
7
|
padding: number;
|
|
8
8
|
horizontalAlignment: HorizontalAlignment;
|
|
9
|
+
trimWhitespace?: boolean;
|
|
9
10
|
}): {
|
|
10
11
|
text: string;
|
|
11
12
|
marginLeft: number;
|
package/lib/table.js
CHANGED
|
@@ -34,7 +34,7 @@ function determineTruncatePosition(overflow) {
|
|
|
34
34
|
}
|
|
35
35
|
}
|
|
36
36
|
}
|
|
37
|
-
export function formatTextWithMargins({ horizontalAlignment, overflow, padding, value, width
|
|
37
|
+
export function formatTextWithMargins({ horizontalAlignment, overflow, padding, trimWhitespace = true, value, width }) {
|
|
38
38
|
function calculateMargins(spaces) {
|
|
39
39
|
let marginLeft;
|
|
40
40
|
let marginRight;
|
|
@@ -76,7 +76,7 @@ export function formatTextWithMargins({ horizontalAlignment, overflow, padding,
|
|
|
76
76
|
if (overflow === 'wrap') {
|
|
77
77
|
const wrappedText = wrapAnsi(valueWithNoZeroWidthChars, spaceForText, {
|
|
78
78
|
hard: true,
|
|
79
|
-
trim:
|
|
79
|
+
trim: trimWhitespace,
|
|
80
80
|
wordWrap: true,
|
|
81
81
|
}).replace(/^\n/, ''); // remove leading newline (wrapAnsi adds it to emojis)
|
|
82
82
|
const { marginLeft, marginRight } = calculateMargins(width - determineWidthOfWrappedText(stripAnsi(wrappedText)));
|
|
@@ -114,7 +114,7 @@ export function formatTextWithMargins({ horizontalAlignment, overflow, padding,
|
|
|
114
114
|
};
|
|
115
115
|
}
|
|
116
116
|
function setupTable(props) {
|
|
117
|
-
const { data, filter, horizontalAlignment = 'left', maxWidth, noStyle = false, overflow = 'truncate', padding = 1, sort, title, verticalAlignment = 'top', width, } = props;
|
|
117
|
+
const { data, filter, horizontalAlignment = 'left', maxWidth, noStyle = false, overflow = 'truncate', padding = 1, sort, title, trimWhitespace, verticalAlignment = 'top', width, } = props;
|
|
118
118
|
const headerOptions = noStyle ? {} : { bold: true, color: 'blue', ...props.headerOptions };
|
|
119
119
|
const borderStyle = noStyle ? 'none' : (props.borderStyle ?? 'all');
|
|
120
120
|
const borderColor = noStyle ? undefined : props.borderColor;
|
|
@@ -131,6 +131,7 @@ function setupTable(props) {
|
|
|
131
131
|
maxWidth: tableWidth ?? determineConfiguredWidth(maxWidth),
|
|
132
132
|
overflow,
|
|
133
133
|
padding,
|
|
134
|
+
trimWhitespace,
|
|
134
135
|
verticalAlignment,
|
|
135
136
|
width: tableWidth,
|
|
136
137
|
};
|
|
@@ -146,6 +147,7 @@ function setupTable(props) {
|
|
|
146
147
|
borderProps,
|
|
147
148
|
cell: Cell,
|
|
148
149
|
skeleton: BORDER_SKELETONS[config.borderStyle].data,
|
|
150
|
+
trimWhitespace
|
|
149
151
|
});
|
|
150
152
|
const footerComponent = row({
|
|
151
153
|
borderProps,
|
|
@@ -217,7 +219,7 @@ export function Table(props) {
|
|
|
217
219
|
*/
|
|
218
220
|
function row(config) {
|
|
219
221
|
// This is a component builder. We return a function.
|
|
220
|
-
const { borderProps, skeleton } = config;
|
|
222
|
+
const { borderProps, skeleton, trimWhitespace } = config;
|
|
221
223
|
return (props) => {
|
|
222
224
|
const data = props.columns.map((column, colI) => {
|
|
223
225
|
const { horizontalAlignment, overflow, padding, verticalAlignment, width } = column;
|
|
@@ -231,6 +233,7 @@ function row(config) {
|
|
|
231
233
|
horizontalAlignment,
|
|
232
234
|
overflow,
|
|
233
235
|
padding,
|
|
236
|
+
trimWhitespace,
|
|
234
237
|
value,
|
|
235
238
|
width,
|
|
236
239
|
});
|
|
@@ -323,6 +326,7 @@ function renderPlainTable(props) {
|
|
|
323
326
|
horizontalAlignment,
|
|
324
327
|
overflow,
|
|
325
328
|
padding,
|
|
329
|
+
trimWhitespace: props.trimWhitespace,
|
|
326
330
|
value: headings[column.column] ?? column.column,
|
|
327
331
|
width,
|
|
328
332
|
});
|
|
@@ -360,6 +364,7 @@ function renderPlainTable(props) {
|
|
|
360
364
|
horizontalAlignment,
|
|
361
365
|
overflow,
|
|
362
366
|
padding,
|
|
367
|
+
trimWhitespace: props.trimWhitespace,
|
|
363
368
|
value,
|
|
364
369
|
width,
|
|
365
370
|
});
|
package/lib/types.d.ts
CHANGED
|
@@ -165,6 +165,11 @@ export type TableOptions<T extends Record<string, unknown>> = {
|
|
|
165
165
|
* Title of the table. Displayed above the table.
|
|
166
166
|
*/
|
|
167
167
|
title?: string;
|
|
168
|
+
/**
|
|
169
|
+
* Whether or not to trim the whitespace of row content
|
|
170
|
+
* default: true
|
|
171
|
+
*/
|
|
172
|
+
trimWhitespace?: boolean;
|
|
168
173
|
/**
|
|
169
174
|
* Styling options for the title of the table.
|
|
170
175
|
*/
|
|
@@ -181,6 +186,7 @@ export type Config<T> = {
|
|
|
181
186
|
maxWidth: number;
|
|
182
187
|
overflow: Overflow;
|
|
183
188
|
headerOptions: HeaderOptions;
|
|
189
|
+
trimWhitespace: boolean | undefined;
|
|
184
190
|
borderStyle: BorderStyle;
|
|
185
191
|
horizontalAlignment: HorizontalAlignment;
|
|
186
192
|
verticalAlignment: VerticalAlignment;
|
|
@@ -206,6 +212,11 @@ export type RowConfig = {
|
|
|
206
212
|
cross: string;
|
|
207
213
|
line: string;
|
|
208
214
|
};
|
|
215
|
+
/**
|
|
216
|
+
* Whether or not to trim the whitespace of row content
|
|
217
|
+
* default: true
|
|
218
|
+
*/
|
|
219
|
+
trimWhitespace?: boolean;
|
|
209
220
|
props?: Record<string, unknown>;
|
|
210
221
|
borderProps: {
|
|
211
222
|
color: SupportedColor | undefined;
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@oclif/table",
|
|
3
3
|
"description": "Display table in terminal",
|
|
4
|
-
"version": "0.4.
|
|
4
|
+
"version": "0.4.13",
|
|
5
5
|
"author": "Salesforce",
|
|
6
6
|
"bugs": "https://github.com/oclif/table/issues",
|
|
7
7
|
"dependencies": {
|
|
@@ -13,11 +13,11 @@
|
|
|
13
13
|
"object-hash": "^3.0.0",
|
|
14
14
|
"react": "^18.3.1",
|
|
15
15
|
"strip-ansi": "^7.1.0",
|
|
16
|
-
"wrap-ansi": "^9.0.
|
|
16
|
+
"wrap-ansi": "^9.0.2"
|
|
17
17
|
},
|
|
18
18
|
"devDependencies": {
|
|
19
19
|
"@commitlint/config-conventional": "^19",
|
|
20
|
-
"@eslint/compat": "^1.3.
|
|
20
|
+
"@eslint/compat": "^1.3.2",
|
|
21
21
|
"@oclif/core": "^4",
|
|
22
22
|
"@oclif/prettier-config": "^0.2.1",
|
|
23
23
|
"@oclif/test": "^4.1.13",
|
|
@@ -29,10 +29,10 @@
|
|
|
29
29
|
"ansis": "^3.17.0",
|
|
30
30
|
"chai": "^4.5.0",
|
|
31
31
|
"commitlint": "^19",
|
|
32
|
-
"eslint": "^9.
|
|
33
|
-
"eslint-config-oclif": "^6.0.
|
|
32
|
+
"eslint": "^9.35.0",
|
|
33
|
+
"eslint-config-oclif": "^6.0.101",
|
|
34
34
|
"eslint-config-prettier": "^10.1.8",
|
|
35
|
-
"eslint-config-xo": "^0.
|
|
35
|
+
"eslint-config-xo": "^0.49.0",
|
|
36
36
|
"eslint-config-xo-react": "^0.28.0",
|
|
37
37
|
"eslint-plugin-react": "^7.37.5",
|
|
38
38
|
"eslint-plugin-react-hooks": "^4.6.2",
|