Comparing version 1.0.0 to 1.0.1
@@ -0,1 +1,5 @@ | ||
// taken from https://github.com/chalk/ansi-regex/blob/master/index.js because | ||
// it's not very safe to import 2 modules to get 1 line of code | ||
const ansi = new RegExp('[\\u001B\\u009B][[\\]()#;?]*(?:(?:(?:[a-zA-Z\\d]*(?:;[a-zA-Z\\d]*)*)?\\u0007)|(?:(?:\\d{1,4}(?:;\\d{0,4})*)?[\\dA-PRZcf-ntqry=><~]))', 'g') | ||
module.exports = function table (arr, padding = 2) { | ||
@@ -5,3 +9,3 @@ const width = [] | ||
subArr.forEach((e, i) => { | ||
width[i] = Math.max(width[i] || 0, e.length) | ||
width[i] = Math.max(width[i] || 0, e.replace(ansi, '').length) | ||
}) | ||
@@ -13,3 +17,3 @@ }) | ||
subArr.forEach((e, i) => { | ||
ret += e + ' '.repeat(width[i] - e.length) + | ||
ret += e + ' '.repeat(width[i] - e.replace(ansi, '').length) + | ||
((i === subArr.length - 1) ? '\n' : ' '.repeat(padding)) | ||
@@ -16,0 +20,0 @@ }) |
{ | ||
"name": "good-table", | ||
"version": "1.0.0", | ||
"version": "1.0.1", | ||
"description": "format array of arrays as a table with no config", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
1551
19