1- const _ = require ( 'lodash' )
2- const chalk = require ( 'chalk' )
3- const Table = require ( 'cli-table3' )
4- const utils = require ( 'cli-table3/src/utils' )
5- const widestLine = require ( 'widest-line' )
6- const terminalSize = require ( './terminal-size' )
1+ import _ from 'lodash'
2+ import chalk from 'chalk'
3+ import Table from 'cli-table3'
4+ import utils from 'cli-table3/src/utils'
5+ import widestLine from 'widest-line'
6+ import { get as getTerminalSize } from './terminal-size'
7+ import type { HorizontalAlignment } from 'cli-table3'
78
89const MAXIMUM_SIZE = 100
910const EXPECTED_SUM = 100
1011
11- const getMaximumColumns = ( ) => {
12+ export const getMaximumColumns = ( ) => {
1213 // get the maximum amount of columns
1314 // that can fit in the terminal
14- return Math . min ( MAXIMUM_SIZE , terminalSize . get ( ) . columns )
15+ return Math . min ( MAXIMUM_SIZE , getTerminalSize ( ) . columns )
1516}
1617
1718const getBordersLength = ( left , right ) => {
@@ -23,9 +24,9 @@ const getBordersLength = (left, right) => {
2324 . value ( )
2425}
2526
26- const renderTables = ( ...tables ) => {
27+ export const renderTables = ( ...tables ) => {
2728 return _
28- . chain ( [ ] )
29+ . chain < string [ ] > ( [ ] )
2930 . concat ( tables )
3031 . invokeMap ( 'toString' )
3132 . join ( '\n' )
@@ -130,7 +131,7 @@ const wrapBordersInGray = (chars) => {
130131 } )
131132}
132133
133- const table = ( options = { } ) => {
134+ export const table = ( options : { type : string , colWidths ?: number [ ] , colAligns ?: string [ ] , head ?: string [ ] , chars ?: Record < string , string > , style ?: { [ key : string ] : any } } ) => {
134135 const { type } = options
135136 const defaults = utils . mergeOptions ( { } )
136137
@@ -161,7 +162,7 @@ const table = (options = {}) => {
161162 if ( bordersLength > 0 ) {
162163 // redistribute the columns to account for borders on each side...
163164 // and subtract borders size from the largest width cell
164- const largestCellWidth = _ . max ( colWidths )
165+ const largestCellWidth = _ . max ( colWidths ) ?? 0
165166
166167 const index = _ . indexOf ( colWidths , largestCellWidth )
167168
@@ -174,18 +175,22 @@ const table = (options = {}) => {
174175
175176 options . chars = wrapBordersInGray ( chars )
176177
177- return new Table ( options )
178+ return new Table ( {
179+ ...options ,
180+ colAligns : options . colAligns as HorizontalAlignment [ ] ,
181+ } )
178182}
179183
180- const header = ( message , options = { } ) => {
184+ export const header = ( message : string , options : { color ?: string [ ] | null } = { } ) => {
181185 _ . defaults ( options , {
182186 color : null ,
183187 } )
184188
185189 message = ` (${ chalk . underline . bold ( message ) } )`
186190
187191 if ( options . color ) {
188- const colors = [ ] . concat ( options . color )
192+ // @ts -expect-error
193+ const colors = < string [ ] > [ ] . concat ( options . color )
189194
190195 message = _ . reduce ( colors , ( memo , color ) => {
191196 return chalk [ color ] ( memo )
@@ -195,21 +200,9 @@ const header = (message, options = {}) => {
195200 console . log ( message ) // eslint-disable-line no-console
196201}
197202
198- const divider = ( symbol , color = 'gray' ) => {
203+ export const divider = ( symbol , color = 'gray' ) => {
199204 const cols = getMaximumColumns ( )
200205 const str = symbol . repeat ( cols )
201206
202207 console . log ( chalk [ color ] ( str ) ) // eslint-disable-line no-console
203208}
204-
205- module . exports = {
206- table,
207-
208- header,
209-
210- divider,
211-
212- renderTables,
213-
214- getMaximumColumns,
215- }
0 commit comments