Skip to content

Commit 1abd11b

Browse files
committed
Curry getSeparatorLine
1 parent 7cf40f4 commit 1abd11b

File tree

2 files changed

+14
-15
lines changed

2 files changed

+14
-15
lines changed

src/ascii-data-table.js

Lines changed: 10 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,13 @@ const spacePad = padString(' ')
1010
const stringifyArray = R.cMap(JSON.stringify)
1111
const stringifyRows = (rows) => R.EitherArray(rows).fold(() => null, R.cMap(stringifyArray))
1212
const insertColSeparators = (arr) => '│' + arr.join('│') + '│'
13-
const getTopSeparatorLine = (colWidths) => getSeparatorLine('═', '╒', '╤', '╕', colWidths)
14-
const getThickSeparatorLine = (colWidths) => getSeparatorLine('═', '╞', '╪', '╡', colWidths)
15-
const getThinSeparatorLine = (colWidths) => getSeparatorLine('─', '├', '┼', '┤', colWidths)
16-
const getBottomSeparatorLine = (colWidths) => getSeparatorLine('─', '└', '┴', '┘', colWidths)
17-
const getSeparatorLine = (horChar, leftChar, crossChar, rightChar, colWidths) => {
18-
return leftChar + colWidths.map(function (w) {
19-
return padString(horChar)(w)
20-
}).join(crossChar) + rightChar
13+
const getSeparatorLine = (horChar, leftChar, crossChar, rightChar) => (colWidths) => {
14+
return R.concat(leftChar, colWidths.map((w) => padString(horChar)(w)).join(crossChar), rightChar)
2115
}
16+
const topSeparatorLine = getSeparatorLine('═', '╒', '╤', '╕')
17+
const thickSeparatorLine = getSeparatorLine('═', '╞', '╪', '╡')
18+
const thinSeparatorLine = getSeparatorLine('─', '├', '┼', '┤')
19+
const bottomSeparatorLine = getSeparatorLine('─', '└', '┴', '┘')
2220

2321
const colWidths = (maxWidth, minWidth, input) => {
2422
const inputEither = R.EitherArray(input)
@@ -78,14 +76,14 @@ const main = (rows, maxColWidth = 30, minColWidth = 3) => {
7876
const heights = rowHeights(maxColWidth, rows)
7977
const norm = rowsToLines(maxColWidth, heights, widths, rows)
8078
const header = createLines(R.head(norm))
81-
const separated = R.intersperse(getThinSeparatorLine(widths), R.tail(norm))
79+
const separated = R.intersperse(thinSeparatorLine(widths), R.tail(norm))
8280
const lines = createLines(separated)
8381
return [
84-
getTopSeparatorLine(widths),
82+
topSeparatorLine(widths),
8583
...header,
86-
getThickSeparatorLine(widths),
84+
thickSeparatorLine(widths),
8785
...lines,
88-
getBottomSeparatorLine(widths)
86+
bottomSeparatorLine(widths)
8987
].join('\n')
9088
}
9189

src/functions.js

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -18,9 +18,10 @@ export const splitEvery = (w, a) => {
1818
export const last = (arr) => arr.slice(-1)
1919
export const head = (arr) => arr.slice(0, 1)
2020
export const tail = (arr) => arr.slice(1)
21-
export const concat = (one, two) => {
22-
if (Array.isArray(one)) return [].concat(one, two)
23-
return '' + one + two
21+
export const concat = function (one, two) {
22+
const concatenated = [].concat(...arguments)
23+
if (Array.isArray(one)) return concatenated
24+
return concatenated.join('')
2425
}
2526
export const transpose = (arr) => {
2627
return arr[0].map((_, i) => {

0 commit comments

Comments
 (0)