eldargab / easy-table

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

Doesn't work with multi-line content #18

Open caub opened 6 years ago

caub commented 6 years ago
var Table = require('easy-table')

var data = [
  { id: 123123, desc: 'Something \nawesome', price: 1000.00 },
  { id: 245452, desc: 'Very interesting book', price: 11.45},
  { id: 232323, desc: 'Yet another product', price: 555.55 }
]

var t = new Table

data.forEach(function(product) {
  t.cell('Product Id', product.id)
  t.cell('Description', product.desc)
  t.cell('Price, USD', product.price, Table.number(2))
  t.newRow()
})

console.log(t.toString())
Product Id  Description            Price, USD
----------  ---------------------  ----------
123123      Something 
awesome         1000.00
245452      Very interesting book       11.45
232323      Yet another product        555.55
kevinsimper commented 6 years ago

I was just looking for the same thing 😄 I guess that it would make it a great deal more complicated to detect line break and then format it after that.

It could just create a new row, but if more columns contain a newline, one row could generate multiple extra rows.