index.d.ts 2.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. declare namespace CliTable3 {
  2. type CharName =
  3. "top" |
  4. "top-mid" |
  5. "top-left" |
  6. "top-right" |
  7. "bottom" |
  8. "bottom-mid" |
  9. "bottom-left" |
  10. "bottom-right" |
  11. "left" |
  12. "left-mid" |
  13. "mid" |
  14. "mid-mid" |
  15. "right" |
  16. "right-mid" |
  17. "middle";
  18. type HorizontalAlignment = "left" | "center" | "right";
  19. type VerticalAlignment = "top" | "center" | "bottom";
  20. interface TableOptions {
  21. truncate: string;
  22. colWidths: Array<number | null>;
  23. rowHeights: Array<number | null>;
  24. colAligns: HorizontalAlignment[];
  25. rowAligns: VerticalAlignment[];
  26. head: string[];
  27. wordWrap: boolean;
  28. }
  29. interface TableInstanceOptions extends TableOptions {
  30. chars: Record<CharName, string>;
  31. style: {
  32. "padding-left": number;
  33. "padding-right": number;
  34. head: string[];
  35. border: string[];
  36. compact: boolean;
  37. };
  38. }
  39. interface TableConstructorOptions extends Partial<TableOptions> {
  40. chars?: Partial<Record<CharName, string>>;
  41. style?: Partial<TableInstanceOptions["style"]>;
  42. }
  43. type CellValue = boolean | number | string | null | undefined;
  44. interface CellOptions {
  45. content: CellValue;
  46. chars?: Partial<Record<CharName, string>>;
  47. truncate?: string;
  48. colSpan?: number;
  49. rowSpan?: number;
  50. hAlign?: HorizontalAlignment;
  51. vAlign?: VerticalAlignment;
  52. style?: {
  53. "padding-left"?: number;
  54. "padding-right"?: number;
  55. head?: string[];
  56. border?: string[];
  57. };
  58. }
  59. interface GenericTable<T> extends Array<T> {
  60. options: TableInstanceOptions;
  61. readonly width: number;
  62. }
  63. type Table = GenericTable<HorizontalTableRow|VerticalTableRow|CrossTableRow>;
  64. type Cell = CellValue | CellOptions;
  65. type HorizontalTableRow = Cell[];
  66. interface VerticalTableRow {
  67. [name: string]: Cell;
  68. }
  69. interface CrossTableRow {
  70. [name: string]: Cell[];
  71. }
  72. }
  73. interface CliTable3 {
  74. new (options?: CliTable3.TableConstructorOptions): CliTable3.Table;
  75. readonly prototype: CliTable3.Table;
  76. }
  77. declare const CliTable3: CliTable3;
  78. export = CliTable3;