index.d.ts 2.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293
  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 | 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. style?: {
  54. "padding-left"?: number;
  55. "padding-right"?: number;
  56. head?: string[];
  57. border?: string[];
  58. };
  59. }
  60. interface GenericTable<T> extends Array<T> {
  61. options: TableInstanceOptions;
  62. readonly width: number;
  63. }
  64. type Table = GenericTable<HorizontalTableRow|VerticalTableRow|CrossTableRow>;
  65. type Cell = CellValue | CellOptions;
  66. type HorizontalTableRow = Cell[];
  67. interface VerticalTableRow {
  68. [name: string]: Cell;
  69. }
  70. interface CrossTableRow {
  71. [name: string]: Cell[];
  72. }
  73. }
  74. interface CliTable3 {
  75. new (options?: CliTable3.TableConstructorOptions): CliTable3.Table;
  76. readonly prototype: CliTable3.Table;
  77. }
  78. declare const CliTable3: CliTable3;
  79. export = CliTable3;