whatwg / console

Console Standard
https://console.spec.whatwg.org/
Other
272 stars 69 forks source link

REQUEST: Allow object paths as strings to be used in console.table properties #174

Closed zivc closed 4 years ago

zivc commented 4 years ago

Hiya,

Big fan of console.table. I see #21 is open so understand this is very much still a work in progress and the best time to raise a request for a new feature?

One gripe I've come across when using console.table as a utility in debugging or even writing tiny data processing scripts is that I just wish you could render data, and specify labels of complex data structures, such as an attribute on an object on that record.

So if a field contained an array, instead of rendering it as; [ Object, Object, Object, ... 97 more items ]] - it would be nice to choose to show the length of the array instead?

A small example below to help describe it better.

Example;

Source object:

const staff = [{
   name:'Human 1',
   shifts:{
      mon: 'early',
      tue: 'late'
   }
},{
   name:'Human 2',
   shifts: {
      tue:'late',
      wed:'early'
   }
}];

Usage:

console.table(staff, ['name', 'shifts.tue']);

Desired output:

┌─────────┬───────────┬────────────┐
│ (index) │   name    │ shifts.tue │
├─────────┼───────────┼────────────┤
│    0    │ 'Human 1' │   'late'   │
│    1    │ 'Human 2' │   'late'   │
└─────────┴───────────┴────────────┘

Just a thought, maybe a nice to have? Feel free to shoot me down.

Ash

domfarolino commented 4 years ago

Thanks for the feature request, much appreciated. I think kind of request is better suited as a comment on https://github.com/whatwg/console/issues/21 to influence the direction of the work being done there. However, I will also note that unfortunately there are no immediate plans to standardize the table method :/ (but feel free to take a stab if you'd like!)

Closing this for now, and if you could comment your idea over on that thread that'd be great