@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 CHANGED
@@ -1,2 +1,2 @@
1
- export { makeTable, makeTables } from './table.js';
2
- export type { TableProps } from './types.js';
1
+ export { printTable, printTables } from './table.js';
2
+ export type { TableOptions } from './types.js';
package/lib/index.js CHANGED
@@ -1 +1 @@
1
- export { makeTable, makeTables } from './table.js';
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, ScalarDict, TableProps } from './types.js';
3
- export declare function Table<T extends ScalarDict>(props: TableProps<T>): React.JSX.Element;
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 TableProps}
20
+ * @param options see {@link TableOptions}
21
21
  */
22
- export declare function makeTable<T extends ScalarDict>(options: TableProps<T>): void;
23
- export declare function makeTables<T extends ScalarDict[]>(tables: {
24
- [P in keyof T]: TableProps<T[P]>;
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 TableProps}
218
+ * @param options see {@link TableOptions}
219
219
  */
220
- export function makeTable(options) {
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 makeTables(tables, options) {
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 TableProps<T extends ScalarDict> = {
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
- * makeTable({data, sort: {name: 'asc'}})
122
+ * printTable({data, sort: {name: 'asc'}})
127
123
  *
128
124
  * // sort the name column in descending order
129
- * makeTable({data, sort: {name: 'desc'}})
125
+ * printTable({data, sort: {name: 'desc'}})
130
126
  *
131
127
  * // sort by name in ascending order and age in descending order
132
- * makeTable({data, sort: {name: 'asc', age: 'desc'}})
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
- * makeTable({data, sort: {name: 'asc', age: (a, b) => b - a}})
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 ScalarDict> = {
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, ScalarDict, Sort } from './types.js';
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 ScalarDict>(data: T[], sort?: Sort<T> | undefined): T[];
12
- export declare function allKeysInCollection<T extends ScalarDict>(data: T[]): (keyof T)[];
13
- export declare function getColumns<T extends ScalarDict>(config: Config<T>, headings: Partial<T>): Column<T>[];
14
- export declare function getHeadings<T extends ScalarDict>(config: Config<T>): Partial<T>;
15
- export declare function maybeStripAnsi<T extends ScalarDict[]>(data: T, noStyle: boolean): T;
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;
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.1.0",
4
+ "version": "0.1.2",
5
5
  "author": "Salesforce",
6
6
  "bugs": "https://github.com/oclif/multi-stage-output/issues",
7
7
  "dependencies": {