type TableFieldDefinitionBase = { /** * If included, overrides the default label for the column. */ label?: string; /** * Use this function if you want to optionally include this field. * * If this function is defined and it returns `false`, the field will * be skipped. This really only makes sense in tables that are * "single item" tables where the first column is the label * and the second is the display value (i.e. tables built with * `TableGenerator.buildTableFromItem`.) */ include?: (i: T) => boolean; /** * If included and set to true, skip the row if it the value is empty. * This is a shortcut for an `include` method that would just do that * check. Like include, this is only valid for single-item tables. */ skipEmpty?: boolean; }; /** * Simplest table field definition that specifies a property name as the definition. * * The label for the field will be derived from the name of the property. */ export type SimpleTableFieldDefinition = keyof T; /** * A `TableFieldDefinition` where the property is specified as a direct property * of the input type. * * The default label (when not overridden with the `label` option) is the string version of `prop` * with the first letter made uppercase and spaces added before other uppercase letters. */ export type PropertyTableFieldDefinition = TableFieldDefinitionBase & { /** * The name of the property from which to get data. */ prop: keyof T; }; /** * A `TableFieldDefinition` where the property is specified as a string given to the `lodash.at` * method. * * The default label is also derived from the final property of the path when the `label` option is * not included. */ export type PathTableFieldDefinition = TableFieldDefinitionBase & { /** * The lodash path of property from which to get data. This is used to reference a nested * property. If you want to reference a non-nested property use `PropertyTableFieldDefinition` * or even `SimpleTableFieldDDefinition` instead. * * The lodash.at function is used to access the property but any path * used should return a single value. * * https://lodash.com/docs#at */ path: `${Extract}.${string}`; }; /** * If a simple property is not good enough to specify the value, you can use this * `TableFieldDefinition` to specify a function which calculates the value of the field. Note * that for this type of `TableFieldDefinition`, the `label` option is required. */ export type ValueTableFieldDefinition = TableFieldDefinitionBase & { /** * If included, overrides the default label for the column. */ label: string; /** * If included, the displayValue function will be called to get the value * to be displayed. If not, the property of the given name, coerced * to a string, will be used. */ value: (i: T) => string | undefined; }; /** * Used to define a field in an output table. * * If the name of the property can programmatically be converted to the name * of the header, a simple string can be used. For example, if the name of * the field is "maxValue", using the string "maxValue" here will result * in a heading name of "Max Value" and data is retrieved from the "maxValue" property. * * If more control is needed, a more complex definition can be included. * * Leaving out both label and value is the equivalent of using a simple string * for the definition. */ export type TableFieldDefinition = SimpleTableFieldDefinition | PropertyTableFieldDefinition | PathTableFieldDefinition | ValueTableFieldDefinition; export type TableGenerator = { newOutputTable(options?: Partial): Table; /** * Build a table for a specific item. There will be no header and the table * will have two columns. The first displays the label for each property * and the second the associated value. */ buildTableFromItem(item: T, tableFieldDefinitions: TableFieldDefinition[]): string; /** * Build a table for a list of items. The first row will be the header row, * displaying labels for all the tableFieldDefinitions and there will be * one row for each item in the items list displaying the associated values. */ buildTableFromList(items: T[], tableFieldDefinitions: TableFieldDefinition[]): string; }; export type TableOptions = { /** * Separate groups of four rows by a line to make long rows easier to follow across the screen. */ groupRows: boolean; head: string[]; isList?: boolean; }; export type TableCellData = string | number | boolean | undefined; export type Table = { push: (row: TableCellData[]) => void; toString: () => string; }; export declare const defaultTableGenerator: (tableOptions: Pick) => TableGenerator; export {}; //# sourceMappingURL=table-generator.d.ts.map