index.d.ts 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596
  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. wrapOnWordBoundary: boolean;
  29. }
  30. interface TableInstanceOptions extends TableOptions {
  31. chars: Record<CharName, string>;
  32. style: {
  33. "padding-left": number;
  34. "padding-right": number;
  35. head: string[];
  36. border: string[];
  37. compact: boolean;
  38. };
  39. }
  40. interface TableConstructorOptions extends Partial<TableOptions> {
  41. chars?: Partial<Record<CharName, string>>;
  42. style?: Partial<TableInstanceOptions["style"]>;
  43. }
  44. type CellValue = boolean | number | bigint | string | null | undefined;
  45. interface CellOptions {
  46. content: CellValue;
  47. chars?: Partial<Record<CharName, string>>;
  48. truncate?: string;
  49. colSpan?: number;
  50. rowSpan?: number;
  51. hAlign?: HorizontalAlignment;
  52. vAlign?: VerticalAlignment;
  53. wordWrap?: boolean;
  54. wrapOnWordBoundary?: boolean;
  55. href?: string;
  56. style?: {
  57. "padding-left"?: number;
  58. "padding-right"?: number;
  59. head?: string[];
  60. border?: string[];
  61. };
  62. }
  63. interface GenericTable<T> extends Array<T> {
  64. options: TableInstanceOptions;
  65. readonly width: number;
  66. }
  67. type Table = GenericTable<HorizontalTableRow|VerticalTableRow|CrossTableRow>;
  68. type Cell = CellValue | CellOptions;
  69. type HorizontalTableRow = Cell[];
  70. interface VerticalTableRow {
  71. [name: string]: Cell;
  72. }
  73. interface CrossTableRow {
  74. [name: string]: Cell[];
  75. }
  76. }
  77. interface CliTable3 {
  78. new (options?: CliTable3.TableConstructorOptions): CliTable3.Table;
  79. readonly prototype: CliTable3.Table;
  80. }
  81. declare const CliTable3: CliTable3;
  82. export = CliTable3;