New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Support for console.table like output #920
Comments
You can already do this yourself (for example with lib https://github.com/AllMightySauron/ascii-table3). Example below assumes an array of objects (all with the same structure) is passed: import { AsciiTable3, AlignmentEnum } from 'ascii-table3'
debug.formatters.t = function ({ title, data }) {
if (!arr.length) return
const headings = Object.keys(data[0])
const table = new AsciiTable3()
table.setHeading.apply(table, headings)
table.setAlign(3, AlignmentEnum.CENTER)
table.addRowMatrix(data.map((item) => Object.values(item))
return table.toString()
}
// usage
debug('%t', { title: 'my log', data: [ { id: 1 }, { id: 2 } ] }) The formatting is quite some logic so I would argue this is outside the scope of debug-js |
+1 to |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
The format of the output when using
console.table
in javascript is great. It would be awesome to have the debug function support this format of output for arrays of objects.For example, something like this, perhaps with a %t formatter?
The text was updated successfully, but these errors were encountered: