Skip to content

Commit

Permalink
Simplify code
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Feb 20, 2022
1 parent 06b2b03 commit f753ff8
Show file tree
Hide file tree
Showing 4 changed files with 8 additions and 12 deletions.
4 changes: 2 additions & 2 deletions src/report/utils/center.js
Original file line number Diff line number Diff line change
@@ -1,10 +1,10 @@
import { getStringWidth } from './string_width.js'
import stringWidth from 'string-width'

// Center a string at a specific `index` inside a container of a given `width`
// Ensures the string is usually centered around `index` except when at the
// start or end of the container.
export const centerString = function (string, index, width) {
const stringLength = getStringWidth(string)
const stringLength = stringWidth(string)
const leftShift = Math.max(Math.floor((stringLength - 1) / 2), 0)
const shiftedIndex = index - leftShift
const maxIndex = width - stringLength
Expand Down
4 changes: 2 additions & 2 deletions src/report/utils/pad.js
Original file line number Diff line number Diff line change
@@ -1,8 +1,8 @@
import { getStringWidth } from './string_width.js'
import stringWidth from 'string-width'

// Pad string. Unlike `string.pad*()`, this works with ANSI sequences.
export const padString = function (string, width) {
const paddingWidth = width - getStringWidth(string)
const paddingWidth = width - stringWidth(string)
const padding = ' '.repeat(paddingWidth)
return `${padding}${string}`
}
5 changes: 0 additions & 5 deletions src/report/utils/string_width.js

This file was deleted.

7 changes: 4 additions & 3 deletions src/report/utils/table/main.js
Original file line number Diff line number Diff line change
@@ -1,9 +1,10 @@
import stringWidth from 'string-width'

import {
TITLE_SEPARATOR,
getColSeparator,
getColSeparatorColored,
} from '../separator.js'
import { getStringWidth } from '../string_width.js'

import { getTablesRows } from './rows.js'
import { getSingleTable } from './single.js'
Expand All @@ -21,8 +22,8 @@ import { getSingleTable } from './single.js'
export const getTables = function (rows, screenWidth, mini = false) {
const rowsLeft = rows.map(getRowLeft)
const rowsRight = rows.map(getRowRight)
const leftWidth = Math.max(...rowsLeft.map(getStringWidth))
const columnsWidth = Math.max(...rowsRight.flat().map(getStringWidth))
const leftWidth = Math.max(...rowsLeft.map(stringWidth))
const columnsWidth = Math.max(...rowsRight.flat().map(stringWidth))
const availableWidth = getAvailableWidth(screenWidth, leftWidth)
const columnSeparator = getColSeparator(mini)
const columnSeparatorColored = getColSeparatorColored(mini)
Expand Down

0 comments on commit f753ff8

Please sign in to comment.