@oclif/table 0.1.0 → 0.1.2
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/index.d.ts +2 -2
- package/lib/index.js +1 -1
- package/lib/table.d.ts +6 -6
- package/lib/table.js +3 -3
- package/lib/types.d.ts +6 -10
- package/lib/utils.d.ts +6 -6
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export {
|
|
2
|
-
export type {
|
|
1
|
+
export { printTable, printTables } from './table.js';
|
|
2
|
+
export type { TableOptions } from './types.js';
|
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export {
|
|
1
|
+
export { printTable, printTables } from './table.js';
|
package/lib/table.d.ts
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { CellProps, ContainerProps,
|
|
3
|
-
export declare function Table<T extends
|
|
2
|
+
import { CellProps, ContainerProps, TableOptions } from './types.js';
|
|
3
|
+
export declare function Table<T extends Record<string, unknown>>(props: TableOptions<T>): React.JSX.Element;
|
|
4
4
|
/**
|
|
5
5
|
* Renders the header of a table.
|
|
6
6
|
*/
|
|
@@ -17,9 +17,9 @@ export declare function Skeleton(props: React.PropsWithChildren & {
|
|
|
17
17
|
}): React.JSX.Element;
|
|
18
18
|
/**
|
|
19
19
|
* Renders a table with the given data.
|
|
20
|
-
* @param options see {@link
|
|
20
|
+
* @param options see {@link TableOptions}
|
|
21
21
|
*/
|
|
22
|
-
export declare function
|
|
23
|
-
export declare function
|
|
24
|
-
[P in keyof T]:
|
|
22
|
+
export declare function printTable<T extends Record<string, unknown>>(options: TableOptions<T>): void;
|
|
23
|
+
export declare function printTables<T extends Record<string, unknown>[]>(tables: {
|
|
24
|
+
[P in keyof T]: TableOptions<T[P]>;
|
|
25
25
|
}, options?: Omit<ContainerProps, 'children'>): void;
|
package/lib/table.js
CHANGED
|
@@ -215,16 +215,16 @@ export function Skeleton(props) {
|
|
|
215
215
|
}
|
|
216
216
|
/**
|
|
217
217
|
* Renders a table with the given data.
|
|
218
|
-
* @param options see {@link
|
|
218
|
+
* @param options see {@link TableOptions}
|
|
219
219
|
*/
|
|
220
|
-
export function
|
|
220
|
+
export function printTable(options) {
|
|
221
221
|
const instance = render(React.createElement(Table, { ...options }));
|
|
222
222
|
instance.unmount();
|
|
223
223
|
}
|
|
224
224
|
function Container(props) {
|
|
225
225
|
return (React.createElement(Box, { flexWrap: "wrap", flexDirection: props.direction ?? 'row', ...props }, props.children));
|
|
226
226
|
}
|
|
227
|
-
export function
|
|
227
|
+
export function printTables(tables, options) {
|
|
228
228
|
const leftMargin = options?.marginLeft ?? options?.margin ?? 0;
|
|
229
229
|
const rightMargin = options?.marginRight ?? options?.margin ?? 0;
|
|
230
230
|
const columns = process.stdout.columns - (leftMargin + rightMargin);
|
package/lib/types.d.ts
CHANGED
|
@@ -1,8 +1,4 @@
|
|
|
1
1
|
import { BorderStyle } from './skeletons.js';
|
|
2
|
-
export type Scalar = string | number | boolean | null | undefined;
|
|
3
|
-
export type ScalarDict = {
|
|
4
|
-
[key: string]: Scalar;
|
|
5
|
-
};
|
|
6
2
|
export type CellProps = React.PropsWithChildren<{
|
|
7
3
|
readonly column: number;
|
|
8
4
|
}>;
|
|
@@ -60,7 +56,7 @@ type SortOrder<T> = 'asc' | 'desc' | ((valueA: T, valueB: T) => number);
|
|
|
60
56
|
export type Sort<T> = {
|
|
61
57
|
[K in keyof T]?: SortOrder<T[K]>;
|
|
62
58
|
};
|
|
63
|
-
export type
|
|
59
|
+
export type TableOptions<T extends Record<string, unknown>> = {
|
|
64
60
|
/**
|
|
65
61
|
* List of values (rows).
|
|
66
62
|
*/
|
|
@@ -123,16 +119,16 @@ export type TableProps<T extends ScalarDict> = {
|
|
|
123
119
|
* ]
|
|
124
120
|
*
|
|
125
121
|
* // sort the name column in ascending order
|
|
126
|
-
*
|
|
122
|
+
* printTable({data, sort: {name: 'asc'}})
|
|
127
123
|
*
|
|
128
124
|
* // sort the name column in descending order
|
|
129
|
-
*
|
|
125
|
+
* printTable({data, sort: {name: 'desc'}})
|
|
130
126
|
*
|
|
131
127
|
* // sort by name in ascending order and age in descending order
|
|
132
|
-
*
|
|
128
|
+
* printTable({data, sort: {name: 'asc', age: 'desc'}})
|
|
133
129
|
*
|
|
134
130
|
* // sort by name in ascending order and age in descending order using a custom sort function
|
|
135
|
-
*
|
|
131
|
+
* printTable({data, sort: {name: 'asc', age: (a, b) => b - a}})
|
|
136
132
|
* ```
|
|
137
133
|
*/
|
|
138
134
|
sort?: Sort<T>;
|
|
@@ -208,7 +204,7 @@ export type RowConfig = {
|
|
|
208
204
|
color: SupportedColor | undefined;
|
|
209
205
|
};
|
|
210
206
|
};
|
|
211
|
-
export type RowProps<T extends
|
|
207
|
+
export type RowProps<T extends Record<string, unknown>> = {
|
|
212
208
|
readonly key: string;
|
|
213
209
|
readonly data: Partial<T>;
|
|
214
210
|
readonly columns: Column<T>[];
|
package/lib/utils.d.ts
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Column, Config,
|
|
1
|
+
import { Column, Config, Sort } from './types.js';
|
|
2
2
|
/**
|
|
3
3
|
* Intersperses a list of elements with another element.
|
|
4
4
|
*
|
|
@@ -8,8 +8,8 @@ import { Column, Config, ScalarDict, Sort } from './types.js';
|
|
|
8
8
|
* ```
|
|
9
9
|
*/
|
|
10
10
|
export declare function intersperse<T, I>(intersperser: (index: number) => I, elements: T[]): (T | I)[];
|
|
11
|
-
export declare function sortData<T extends
|
|
12
|
-
export declare function allKeysInCollection<T extends
|
|
13
|
-
export declare function getColumns<T extends
|
|
14
|
-
export declare function getHeadings<T extends
|
|
15
|
-
export declare function maybeStripAnsi<T extends
|
|
11
|
+
export declare function sortData<T extends Record<string, unknown>>(data: T[], sort?: Sort<T> | undefined): T[];
|
|
12
|
+
export declare function allKeysInCollection<T extends Record<string, unknown>>(data: T[]): (keyof T)[];
|
|
13
|
+
export declare function getColumns<T extends Record<string, unknown>>(config: Config<T>, headings: Partial<T>): Column<T>[];
|
|
14
|
+
export declare function getHeadings<T extends Record<string, unknown>>(config: Config<T>): Partial<T>;
|
|
15
|
+
export declare function maybeStripAnsi<T extends Record<string, unknown>[]>(data: T, noStyle: boolean): T;
|