@oclif/table 0.1.24 → 0.2.0
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 +1 -1
- package/lib/index.js +1 -1
- package/lib/table.d.ts +22 -2
- package/lib/table.js +27 -2
- package/package.json +1 -1
package/lib/index.d.ts
CHANGED
|
@@ -1,2 +1,2 @@
|
|
|
1
|
-
export { printTable, printTables } from './table.js';
|
|
1
|
+
export { makeTable, printTable, printTables } from './table.js';
|
|
2
2
|
export type { TableOptions } from './types.js';
|
package/lib/index.js
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
export { printTable, printTables } from './table.js';
|
|
1
|
+
export { makeTable, printTable, printTables } from './table.js';
|
package/lib/table.d.ts
CHANGED
|
@@ -27,10 +27,30 @@ export declare function Skeleton(props: React.PropsWithChildren & {
|
|
|
27
27
|
readonly height?: number;
|
|
28
28
|
}): React.JSX.Element;
|
|
29
29
|
/**
|
|
30
|
-
*
|
|
31
|
-
*
|
|
30
|
+
* Prints a table based on the provided options. If the data length exceeds 50,000 entries,
|
|
31
|
+
* the table is rendered in chunks to handle large datasets efficiently.
|
|
32
|
+
*
|
|
33
|
+
* @template T - A generic type that extends a record with string keys and unknown values.
|
|
34
|
+
* @param {TableOptions<T>} options - The options for rendering the table, including data and other configurations.
|
|
35
|
+
* @returns {void}
|
|
32
36
|
*/
|
|
33
37
|
export declare function printTable<T extends Record<string, unknown>>(options: TableOptions<T>): void;
|
|
38
|
+
/**
|
|
39
|
+
* Generates a table as a string based on the provided options.
|
|
40
|
+
*
|
|
41
|
+
* @template T - A generic type extending a record with string keys and unknown values.
|
|
42
|
+
* @param {TableOptions<T>} options - The options to configure the table.
|
|
43
|
+
* @returns {string} The rendered table as a string.
|
|
44
|
+
*/
|
|
45
|
+
export declare function makeTable<T extends Record<string, unknown>>(options: TableOptions<T>): string;
|
|
46
|
+
/**
|
|
47
|
+
* Prints multiple tables to the console.
|
|
48
|
+
*
|
|
49
|
+
* @template T - An array of records where each record represents a table.
|
|
50
|
+
* @param {Object.<keyof T, TableOptions<T[keyof T]>>} tables - An object containing table options for each table.
|
|
51
|
+
* @param {Omit<ContainerProps, 'children'>} [options] - Optional container properties excluding 'children'.
|
|
52
|
+
* @throws {Error} Throws an error if the total number of rows across all tables exceeds 30,000.
|
|
53
|
+
*/
|
|
34
54
|
export declare function printTables<T extends Record<string, unknown>[]>(tables: {
|
|
35
55
|
[P in keyof T]: TableOptions<T[P]>;
|
|
36
56
|
}, options?: Omit<ContainerProps, 'children'>): void;
|
package/lib/table.js
CHANGED
|
@@ -355,8 +355,12 @@ function renderTableInChunks(props) {
|
|
|
355
355
|
footerOutput.maybePrintLastFrame();
|
|
356
356
|
}
|
|
357
357
|
/**
|
|
358
|
-
*
|
|
359
|
-
*
|
|
358
|
+
* Prints a table based on the provided options. If the data length exceeds 50,000 entries,
|
|
359
|
+
* the table is rendered in chunks to handle large datasets efficiently.
|
|
360
|
+
*
|
|
361
|
+
* @template T - A generic type that extends a record with string keys and unknown values.
|
|
362
|
+
* @param {TableOptions<T>} options - The options for rendering the table, including data and other configurations.
|
|
363
|
+
* @returns {void}
|
|
360
364
|
*/
|
|
361
365
|
export function printTable(options) {
|
|
362
366
|
if (options.data.length > 50_000) {
|
|
@@ -368,9 +372,30 @@ export function printTable(options) {
|
|
|
368
372
|
instance.unmount();
|
|
369
373
|
output.maybePrintLastFrame();
|
|
370
374
|
}
|
|
375
|
+
/**
|
|
376
|
+
* Generates a table as a string based on the provided options.
|
|
377
|
+
*
|
|
378
|
+
* @template T - A generic type extending a record with string keys and unknown values.
|
|
379
|
+
* @param {TableOptions<T>} options - The options to configure the table.
|
|
380
|
+
* @returns {string} The rendered table as a string.
|
|
381
|
+
*/
|
|
382
|
+
export function makeTable(options) {
|
|
383
|
+
const output = new Output();
|
|
384
|
+
const instance = render(React.createElement(Table, { ...options }), { stdout: output.stream });
|
|
385
|
+
instance.unmount();
|
|
386
|
+
return output.stream.lastFrame() ?? '';
|
|
387
|
+
}
|
|
371
388
|
function Container(props) {
|
|
372
389
|
return (React.createElement(Box, { flexWrap: "wrap", flexDirection: props.direction ?? 'row', ...props }, props.children));
|
|
373
390
|
}
|
|
391
|
+
/**
|
|
392
|
+
* Prints multiple tables to the console.
|
|
393
|
+
*
|
|
394
|
+
* @template T - An array of records where each record represents a table.
|
|
395
|
+
* @param {Object.<keyof T, TableOptions<T[keyof T]>>} tables - An object containing table options for each table.
|
|
396
|
+
* @param {Omit<ContainerProps, 'children'>} [options] - Optional container properties excluding 'children'.
|
|
397
|
+
* @throws {Error} Throws an error if the total number of rows across all tables exceeds 30,000.
|
|
398
|
+
*/
|
|
374
399
|
export function printTables(tables, options) {
|
|
375
400
|
if (tables.reduce((acc, table) => acc + table.data.length, 0) > 30_000) {
|
|
376
401
|
throw new Error('The data is too large to print multiple tables. Please use `printTable` instead.');
|