eldargab / easy-table

Nice text table for Node.js
314 stars 31 forks source link

Length function doesn't properly strip out some color data from strings. #20

Closed apexearth closed 6 years ago

apexearth commented 6 years ago

I'm working with npm chalk. When I use the rgb function to create colors, easy-table doesn't strip out the color data properly and I'm left with a funky looking table.

Switching over to npm ansi-regex solves the problem.

function length(str) {
  var s = str.replace(/\u001b\[\d+m/g, '')
  return wcwidth == null ? s.length : wcwidth(s)
}

change to ...

var ansiRegex = require('ansi-regex')
function length(str) {
  var s = str.replace(ansiRegex(), '')
  return wcwidth == null ? s.length : wcwidth(s)
}
eldargab commented 6 years ago

New version released