-
Notifications
You must be signed in to change notification settings - Fork 29.9k
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
console: implement console.table and console.dirxml #17128
Comments
if you're doing dirxml i'd be interested in trying out table |
currently i tried just using // an array of strings
console.table(["apples", "oranges", "bananas"]); // an object whose properties are strings
function Person(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
var me = new Person("John", "Smith");
console.table(me); // an array of arrays
var people = [["John", "Smith"], ["Jane", "Doe"], ["Emily", "Jones"]];
console.table(people); // an array of objects, logging only firstName
function Person(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
var john = new Person("John", "Smith");
var jane = new Person("Jane", "Doe");
var emily = new Person("Emily", "Jones");
console.table([john, jane, emily], ["firstName"]); var family = {};
family.mother = new Person("Jane", "Smith");
family.father = new Person("John", "Smith");
family.daughter = new Person("Emily", "Smith");
console.table(family); |
Awesome! IMHO the width of the columns should be controlled though, and maybe the table be defined with border, so to replicate browser implementation at the best. Thanks for your work! Starting on dirxml today. |
If it matters for any attempts to implement We could have gone with a tab character instead, but didn't in order to be consistent with what the |
...although a tab character might make a lot more sense here for simplicity. I think a simple and lightweight implementation for something like
|
I don't think we want borders or background colors or other things like in the browser. The browser gets to make lots of assumptions about the console environment, but we don't. The more complex it is, the more maintenance problems are likely to come up. I'm feeling pretty +1 on separating with a tab character and not worrying about column widths or things lining up. If they don't line up, then the end user will need to adjust their tab width. That's unfortunate, but not terrible, at least for a first implementation. If there's a huge outcry for more features, they can come later. (And you now have an easy function for making tsv output to boot!) If we want things to line up, it will mean getting the length of everything in the table, tracking it, and padding values appropriately. That's do-able, but bug-prone because you have to worry about things like surrogate pairs. I'm feeling really good about "separate with a tab character and let stuff end up wherever it ends up", although I imagine others might be concerned that we'll get bug reports. Maybe just make it clear in the docs that that is all it does. |
@Trott Without going full length on replicating browser implementation, I think we should at least get a separation character to get a bit clearer. As for userland modules, I think one already exists. Maybe some inspiration can be found there? Although its implementation does not seem full of bells and whistles either tbh... |
Quick question here, for advice. Since Node.js doesn't deal directly with the browser DOM, it doesn't implement any DOMParser. This will evidently cause some problems to implement I mean, the easy way would be to implement Or am I just going through |
I think the best thing Node can do for a situation like that is to provide a symbol that lets you override what |
@addaleax In that case, Or is it so late that I don't understand squat? |
Okay, I've worked out an absolute first draft, and soon will open a PR. I'm currently learning toward providing the possibility to pass a third argument (the first two being the object to inspect and the options object, for consistency with Does that sound okay? |
This is an absolute first draft. This method was previously exposed by V8 (since Node v8.0.0) and not implemented in Node directly. Tests coming soon. Refs: nodejs#17128
First draft: #17146 |
This method was previously exposed by V8 (since Node v8.0.0) and not implemented in Node directly. Tests coming soon. Refs: nodejs#17128
…eceived. Minimal implementation following the Living Standard specs, following reviews. Fixes: nodejs#17128
Nits in documentation, rework dirxml to use console.log, tests. Fixes: nodejs#17128
This method was previously exposed by V8 (since node 8.0.0) but not implemented in node. PR-URL: #17152 Refs: #17128 Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]>
This method was previously exposed by V8 (since node 8.0.0) but not implemented in node. PR-URL: #17152 Refs: #17128 Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]>
This method was previously exposed by V8 (since node 8.0.0) but not implemented in node. PR-URL: #17152 Refs: #17128 Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Anatoli Papirovski <[email protected]> Reviewed-By: Rich Trott <[email protected]> Reviewed-By: James M Snell <[email protected]>
Just noticed, the 10.0 docs list |
@thw0rted you're perfectly right. I'm pretty sure the method has been implemented the last few days/weeks, but I can't find the PR. The docs may not have been updated completely. There's another PR opened, I'll pass your notice |
Hi everyone!
Following #17004 , #17033 and a discussion with @Trott , I'd like to suggest we implement the remainder of the console methods described in the WHATWG living standard.
Most of them are already implemented, the only ones left are
console.table()
andconsole.dirxml()
.Unless everyone thinks it's a waste of time, I'd like to give it a shot. But of course, help will be deeply welcomed.
In any case, I think I'll start off with
console.dirxml()
if it's ok.Comments and advices welcomed!
The text was updated successfully, but these errors were encountered: