diff --git a/src/action/base.ts b/src/action/base.ts index 75b9c155..bcc672c6 100644 --- a/src/action/base.ts +++ b/src/action/base.ts @@ -1,4 +1,4 @@ -import * as _ from 'lodash' +import castArray from 'lodash/castArray' import {inspect} from 'util' /* eslint-disable-next-line @typescript-eslint/interface-name-prefix */ @@ -196,6 +196,6 @@ export class ActionBase { * write to the real stdout/stderr */ protected _write(std: 'stdout' | 'stderr', s: string | string[]) { - this.stdmockOrigs[std].apply(process[std], _.castArray(s) as [string]) + this.stdmockOrigs[std].apply(process[std], castArray(s) as [string]) } } diff --git a/src/list.ts b/src/list.ts index bcaf59ba..04d8f049 100644 --- a/src/list.ts +++ b/src/list.ts @@ -1,6 +1,6 @@ // tslint:disable -import * as _ from 'lodash' +import maxBy from 'lodash/maxBy' import deps from './deps' @@ -17,14 +17,14 @@ export function renderList(items: IListItem[]): string { if (items.length === 0) { return '' } - const maxLength = (_.maxBy(items, '[0].length') as any)[0].length + const maxLength = (maxBy(items, '[0].length') as any)[0].length const lines = items.map(i => { let left = i[0] let right = i[1] if (!right) { return left } - left = `${_.padEnd(left, maxLength)}` + left = left.padEnd(maxLength) right = linewrap(maxLength + 2, right) return `${left} ${right}` }) diff --git a/src/styled/table.ts b/src/styled/table.ts index 1b4c123b..fc815271 100644 --- a/src/styled/table.ts +++ b/src/styled/table.ts @@ -1,8 +1,9 @@ import {flags as F} from '@oclif/command' import {stdtermwidth} from '@oclif/screen' import chalk from 'chalk' +import capitalize from 'lodash/capitalize' +import sumBy from 'lodash/sumBy' import {safeDump} from 'js-yaml' -import * as _ from 'lodash' import {inspect} from 'util' const sw = require('string-width') @@ -19,7 +20,7 @@ class Table { const col = columns[key] const extended = col.extended || false const get = col.get || ((row: any) => row[key]) - const header = typeof col.header === 'string' ? col.header : _.capitalize(key.replace(/_/g, ' ')) + const header = typeof col.header === 'string' ? col.header : capitalize(key.replace(/_/g, ' ')) const minWidth = Math.max(col.minWidth || 0, sw(header) + 1) return { @@ -202,7 +203,7 @@ class Table { if (options['no-truncate'] || (!process.stdout.isTTY && !process.env.CLI_UX_SKIP_TTY_CHECK)) return // don't shorten if there is enough screen width - const dataMaxWidth = _.sumBy(columns, c => c.width!) + const dataMaxWidth = sumBy(columns, c => c.width!) const overWidth = dataMaxWidth - maxWidth if (overWidth <= 0) return @@ -214,15 +215,15 @@ class Table { // if sum(minWidth's) is greater than term width // nothing can be done so // display all as minWidth - const dataMinWidth = _.sumBy(columns, c => c.minWidth!) + const dataMinWidth = sumBy(columns, c => c.minWidth!) if (dataMinWidth >= maxWidth) return // some wiggle room left, add it back to "needy" columns let wiggleRoom = maxWidth - dataMinWidth - const needyCols = _.sortBy(columns.map(c => ({key: c.key, needs: c.maxWidth! - c.width!})), c => c.needs) + const needyCols = columns.map(c => ({key: c.key, needs: c.maxWidth! - c.width!})).sort((a, b) => a.needs - b.needs) for (const {key, needs} of needyCols) { if (!needs) continue - const col = _.find(columns, c => (key === c.key)) + const col = columns.find(c => key === c.key) if (!col) continue if (wiggleRoom > needs) { col.width = col.width! + needs