Skip to content

Commit b3b9e46

Browse files
committed
remove console.log from prettyPrint
1 parent 057e730 commit b3b9e46

File tree

2 files changed

+23
-9
lines changed

2 files changed

+23
-9
lines changed

lib/prettyPrint.js

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,27 @@
77
*/
88

99
module.exports = routes => {
10+
11+
let out = ''
12+
1013
// Calculate column widths
1114
let widths = routes.reduce((acc,row) => {
12-
return [Math.max(acc[0],row[0].length),Math.max(acc[1],row[1].length)]
15+
return [
16+
Math.max(acc[0],Math.max(6,row[0].length)),
17+
Math.max(acc[1],Math.max(5,row[1].length))
18+
]
1319
},[0,0])
1420

15-
console.log('╔══' + ''.padEnd(widths[0],'═') + '══╤══' + ''.padEnd(widths[1],'═') + '══╗')
16-
console.log('║ ' + "\u001b[1m" + 'METHOD'.padEnd(widths[0]) + "\u001b[0m" + ' │ ' + "\u001b[1m" + 'ROUTE'.padEnd(widths[1]) + "\u001b[0m" + ' ║')
17-
console.log('╟──' + ''.padEnd(widths[0],'─') + '──┼──' + ''.padEnd(widths[1],'─') + '──╢')
21+
out += '╔══' + ''.padEnd(widths[0],'═') + '══╤══' + ''.padEnd(widths[1],'═') + '══╗\n'
22+
out += '║ ' + '\u001b[1m' + 'METHOD'.padEnd(widths[0]) + '\u001b[0m' + ' │ ' + '\u001b[1m' + 'ROUTE'.padEnd(widths[1]) + '\u001b[0m' + ' ║\n'
23+
out += '╟──' + ''.padEnd(widths[0],'─') + '──┼──' + ''.padEnd(widths[1],'─') + '──╢\n'
1824
routes.forEach((route,i) => {
19-
console.log('║ ' + route[0].padEnd(widths[0]) + ' │ ' + route[1].padEnd(widths[1]) + ' ║')
20-
if (i < routes.length-1) { console.log('╟──' + ''.padEnd(widths[0],'─') + '──┼──' + ''.padEnd(widths[1],'─') + '──╢') }
25+
out += '║ ' + route[0].padEnd(widths[0]) + ' │ ' + route[1].padEnd(widths[1]) + ' ║\n'
26+
if (i < routes.length-1) {
27+
out += '╟──' + ''.padEnd(widths[0],'─') + '──┼──' + ''.padEnd(widths[1],'─') + '──╢\n'
28+
} // end if
2129
})
22-
console.log('╚══' + ''.padEnd(widths[0],'═') + '══╧══' + ''.padEnd(widths[1],'═') + '══╝')
30+
out += '╚══' + ''.padEnd(widths[0],'═') + '══╧══' + ''.padEnd(widths[1],'═') + '══╝'
31+
32+
return out
2333
}

test/prettyPrint.js

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,8 +9,12 @@ const prettyPrint = require('../lib/prettyPrint')
99
/******************************************************************************/
1010

1111
describe('PrettyPrint Tests:', function() {
12-
it('Execute', function() {
13-
expect(prettyPrint([['GET','/'],['POST','/'],['DELETE','/']])).to.equal(undefined)
12+
it('Minimum header widths', function() {
13+
expect(prettyPrint([['GET','/'],['POST','/'],['DELETE','/']])).to.equal('╔══════════╤═════════╗\n║ \u001b[1mMETHOD\u001b[0m │ \u001b[1mROUTE\u001b[0m ║\n╟──────────┼─────────╢\n║ GET │ / ║\n╟──────────┼─────────╢\n║ POST │ / ║\n╟──────────┼─────────╢\n║ DELETE │ / ║\n╚══════════╧═════════╝')
14+
}) // end it
15+
16+
it('Adjusted header widths', function() {
17+
expect(prettyPrint([['GET','/'],['POST','/testing'],['DELETE','/long-url-path-name']])).to.equal('╔══════════╤═══════════════════════╗\n║ \u001b[1mMETHOD\u001b[0m │ \u001b[1mROUTE \u001b[0m ║\n╟──────────┼───────────────────────╢\n║ GET │ / ║\n╟──────────┼───────────────────────╢\n║ POST │ /testing ║\n╟──────────┼───────────────────────╢\n║ DELETE │ /long-url-path-name ║\n╚══════════╧═══════════════════════╝')
1418
}) // end it
1519

1620
}) // end UTILITY tests

0 commit comments

Comments
 (0)