Skip to content

Commit

Permalink
Fix join.js
Browse files Browse the repository at this point in the history
  • Loading branch information
ehmicky committed Aug 29, 2021
1 parent 90c5bba commit 32d41db
Show file tree
Hide file tree
Showing 6 changed files with 18 additions and 28 deletions.
4 changes: 1 addition & 3 deletions src/report/reporters/debug/main.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { serializeHistograms } from '../../utils/histogram/main.js'
import { joinSections, joinSubSections } from '../../utils/join.js'
import { prettifyStats } from '../../utils/stats/main.js'
import { addTitles } from '../../utils/title.js'

Expand All @@ -17,8 +16,7 @@ const reportTerminal = function ({ combinations, screenWidth, history }) {
showStats: false,
screenWidth,
})
const histogram = joinSubSections(histograms)
return joinSections([tables, timeSeries, histogram])
return [tables, timeSeries, histograms].join('\n\n')
}

export const debug = { reportTerminal, debugStats: true }
3 changes: 1 addition & 2 deletions src/report/reporters/histogram.js
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
import { serializeHistograms } from '../utils/histogram/main.js'
import { joinSubSections } from '../utils/join.js'
import { prettifyStats } from '../utils/stats/main.js'
import { addTitles } from '../utils/title.js'

Expand All @@ -11,7 +10,7 @@ const reportTerminal = function ({ combinations, screenWidth }) {
showStats: true,
screenWidth,
})
return joinSubSections(histograms)
return histograms
}

export const histogram = { reportTerminal }
8 changes: 5 additions & 3 deletions src/report/utils/histogram/main.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,9 +17,11 @@ export const serializeHistograms = function (
) {
const height = DEFAULT_HEIGHT
const width = getContentWidth(combinations, showStats, screenWidth)
return combinations.map((combination) =>
serializeHistogram({ combination, width, height, showStats }),
)
return combinations
.map((combination) =>
serializeHistogram({ combination, width, height, showStats }),
)
.join('\n')
}

const DEFAULT_HEIGHT = 2 * EXTRA_HEIGHT
Expand Down
8 changes: 0 additions & 8 deletions src/report/utils/join.js

This file was deleted.

13 changes: 6 additions & 7 deletions src/report/utils/prettify_value.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ import isPlainObj from 'is-plain-obj'

import { subtitleColor } from './colors.js'
import { indentBlock } from './indent.js'
import { joinSections, joinSubSections } from './join.js'

// Prettify a value by highlighting keys and indenting it
export const prettifyValue = function (value) {
Expand All @@ -23,15 +22,15 @@ export const prettifyValue = function (value) {

const prettifyArray = function (array) {
const prettifiedArray = array.map(prettifyValue).filter(Boolean)
return array.some(isComplex)
? joinSections(prettifiedArray)
: joinSubSections(prettifiedArray)
const newlines = array.some(isComplex) ? '\n\n' : '\n'
return prettifiedArray.join(newlines)
}

const prettifyObject = function (object) {
return joinSubSections(
Object.entries(object).map(prettifyObjectPair).filter(Boolean),
)
return Object.entries(object)
.map(prettifyObjectPair)
.filter(Boolean)
.join('\n')
}

const prettifyObjectPair = function ([name, value]) {
Expand Down
10 changes: 5 additions & 5 deletions src/report/utils/table.js
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
import stringWidth from 'string-width'

import { joinSections } from './join.js'
import { padString } from './pad.js'
import {
NAME_SEPARATOR,
Expand All @@ -25,10 +24,11 @@ export const getTables = function (rows, screenWidth) {
const columnsWidth = Math.max(...rowsRight.flat().map(stringWidth))
const availableWidth = screenWidth - leftWidth - NAME_SEPARATOR.length
const tablesRows = getTablesRows(rowsRight, availableWidth, columnsWidth)
const sections = tablesRows.map((tableRows) =>
getTable({ tableRows, rowsLeft, leftWidth, columnsWidth }),
)
return joinSections(sections)
return tablesRows
.map((tableRows) =>
getTable({ tableRows, rowsLeft, leftWidth, columnsWidth }),
)
.join('\n\n')
}

const getRowLeft = function ([leftCell = '']) {
Expand Down

0 comments on commit 32d41db

Please sign in to comment.