-
Notifications
You must be signed in to change notification settings - Fork 30k
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,util: implement %o as formatting specifier #14545
Comments
There's also
|
So which shall we implement? Or both? |
The difference between Unfortunately browsers didn't implement |
Yeah I'd also be fine with it giving our typical object expansion. @domenic is this about how you'd expect it to work in Node? |
Yeah I'd expect either %o or both %o and %O to map to the usual util.inspect. Especially given that there's no opportunity for interaction it makes sense for them to be similar. If you wanted to come up with some differentiator, you could. E.g., maybe one of them is meant to be more like valid JS syntax, and the other has little annotations like the name of the class or something. Or, %O special-cases certain important Node objects to given them interesting representations beyond just their properties (similar to how %O in browsers on DOM nodes produces an interactive But keeping things simple, and having both be the usual object expansion, also makes sense to me. |
Marking as |
is this still available? I'd like to take a stab at it as a first contribution. |
@gla5001 it would seem so, yes. |
cool. i'll go ahead and work it. Just so i'm clear, it seems like the behavior of the '%o' formatting specifier should match the behavior of the '%j' specifier. Is that correct? |
@gla5001 I do not think so: > const obj = { func: function() {} };
> console.log('%j', obj);
{}
> console.log(util.inspect(obj));
{ func: [Function: func] } JSON output has restrictions the |
@gla5001 No, by the discussion it should just return |
Implementing the %o and %O as formatting specifier for util.format. Based on discussion in issue, this specifier should just call util.inspect to format passed in value. Fixes: nodejs#14545
Implementing the %o and %O formatting specifiers for util.format. Based on discussion in issue, this specifier should just call util.inspect to format the value. PR-URL: #14558 Fixes: #14545 Reviewed-By: Refael Ackermann <[email protected]> Reviewed-By: Roman Reiss <[email protected]> Reviewed-By: Vse Mozhet Byt <[email protected]> Reviewed-By: James M Snell <[email protected]> Reviewed-By: Evan Lucas <[email protected]> Reviewed-By: Timothy Gu <[email protected]> Reviewed-By: Colin Ihrig <[email protected]> Reviewed-By: Tobias Nießen <[email protected]> Reviewed-By: Yuta Hiroto <[email protected]>
console.log()
andutil.format()
support%d
,%i
,%f
, etc. but not%o
for objects which seems to be supported in major browsers.Refs: #10292
/cc @silverwind
The text was updated successfully, but these errors were encountered: