as-table.d.ts 1.0 KB

1234567891011121314151617181920212223242526272829303132
  1. declare function asTable(rows: any[][]): string
  2. declare function asTable(objects: {[column: string]: any}[]): string
  3. declare namespace asTable {
  4. interface Config<T> {
  5. maxTotalWidth: number
  6. minColumnWidths?: number[]
  7. delimiter?: string
  8. dash: string
  9. right: boolean
  10. print(value: T, key?: string | number): string
  11. title(value: string): string
  12. }
  13. type OmitPrint<T> = Pick<T, Exclude<keyof T, 'print'>> & {print: undefined}
  14. type ValidValueType<O, T> = {
  15. [P in keyof O]: T;
  16. }
  17. interface Formatter<T> extends Readonly<Config<T>> {
  18. (rows: T[][]): string
  19. <O extends ValidValueType<O, T>>(objects: O[]): string
  20. configure(cfg: Partial<OmitPrint<Config<any>>>): Formatter<T>
  21. configure<T>(cfg: Partial<Config<T>>): Formatter<T>
  22. }
  23. function configure<T = any>(cfg: Partial<Config<T>>): Formatter<T>
  24. const maxTotalWidth: number
  25. const print: StringConstructor
  26. const title: StringConstructor
  27. const dash: '-'
  28. const right: false
  29. }
  30. export = asTable