Uh oh!
There was an error while loading. Please reload this page.
util: implement %o as formatting specifier - #14558
Conversation
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
vsemozhetbyt
commented
Jul 31, 2017
vsemozhetbyt
commented
Aug 1, 2017
One ubuntu1604-arm64 failure in the CI seems unrelated. @gla5001 Thank you for your contribution! |
Trott
commented
Aug 1, 2017
/cc @Fishrock123 |
jasnell
commented
Aug 1, 2017
This may possibly also need documentation added (I cannot remember how extensively we've documented the formatting specifiers) |
gla5001
commented
Aug 1, 2017
Yup. Overlooked that. I'll update docs |
| * `%j` - JSON. Replaced with the string `'[Circular]'` if the argument | ||
| contains circular references. | ||
| * `%o` - Object. A string representation of an object. | ||
| Similar to `util.inspect()` without options. |
refack
commented
Aug 1, 2017
Is it too late to consider |
refack
commented
Aug 1, 2017
Or if there's no consensus let's implement just one, since changing it later will be |
I think it'd make sense to indent |
gla5001
commented
Aug 1, 2017
So im happy to implement whatever. Just need a consensus on it.
|
refack
commented
Aug 1, 2017
Quoting #14545 (comment)
|
I don't agree with @refack here. I don't think that JSON-ifying is more detailed, rather it is less, as JSON can't represent everything. |
Considering browsers differentiate this by using a |
Nit fix and changing behavior of %o
gla5001
commented
Aug 1, 2017
Should they be the same then? By JSON-ifying one and inspecting the other, you now the option of displaying more or less detail. Which could be useful in some cases? |
| contains circular references. | ||
| * `%o` - Object. A string representation of an object | ||
| with optimally useful formatting. | ||
| * `%O` - Object. A string representation of an object |
There was a problem hiding this comment.
It seems we should state explicitly that JSON stringification is involved here with its restrictions.
There was a problem hiding this comment.
It seems explicit enough if we do have a consensus for this behavior.
refack
commented
Aug 1, 2017
@Fishrock123 So are you suggesting to reverse may suggestion for so tl;dr in terms of "human usefulness" >constnestedObj={
... foo: 'bar',
... foobar: {
.....foo: 'bar',
.....func: function(){}.....}...};>console.log("%j",nestedObj){"foo":"bar","foobar":{"foo":"bar"}}>console.log(JSON.stringify(nestedObj,null,' ')){"foo": "bar","foobar": {"foo": "bar"}}>console.log(util.inspect(nestedObj)){foo: 'bar',foobar: {foo: 'bar',func: [Function: func]}}or go big and >console.log(util.inspect(nestedObj,{showHidden: true,breakLength:10})){foo: 'bar',foobar:
{foo: 'bar',func:
{[Function: func][length]: 0,[name]: 'func',[prototype]: [Object]}}} |
Another idea ( @gla5001 sorry for the noise ), add |
tniessen
commented
Aug 4, 2017
Landed in 211df3f! Thank you for your efforts, great first contribution! 🎉 |
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: #14558Fixes: #14545 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
gla5001
commented
Aug 4, 2017
awesome. thanks! |
tniessen
commented
Aug 4, 2017
Just a few tips for the future:
We are looking forward to your next contribution! |
refack
commented
Aug 4, 2017
@gla5001 congrats on GitHub promoting you from: |
P.S. a nice second contribution might be adding an |
gla5001
commented
Aug 4, 2017
refack
commented
Aug 4, 2017
No issue just my comment above #14558 (comment) |
domenic
commented
Aug 4, 2017
I would not suggest that as a PR, as I doubt it's something the community is interested in (I personally think it's a bad idea). It would need a dedicated issue with discussion and appropriate input from decider-people. |
refack
commented
Aug 4, 2017
Well @gla5001 opening an issue and discussing a new feature is also a nice contribution. |
gla5001
commented
Aug 5, 2017
Starting discussion #14638 |
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: #14558Fixes: #14545 Reviewed-By: Refael Ackermann <refack@gmail.com> Reviewed-By: Roman Reiss <me@silverwind.io> Reviewed-By: Vse Mozhet Byt <vsemozhetbyt@gmail.com> Reviewed-By: James M Snell <jasnell@gmail.com> Reviewed-By: Evan Lucas <evanlucas@me.com> Reviewed-By: Timothy Gu <timothygu99@gmail.com> Reviewed-By: Colin Ihrig <cjihrig@gmail.com> Reviewed-By: Tobias Nießen <tniessen@tnie.de> Reviewed-By: Yuta Hiroto <hello@about-hiroppy.com>
Notable changes * **Inspector** * `require()` is available in the inspector console now. [#8837](#8837) * **N-API** * New APIs for creating number values have been introduced. [#14573](#14573) * **Stream** * For `Duplex` streams, the high water mark option can now be set independently for the readable and the writable side. [#14636](#14636) * **Util** * `util.format` now supports the `%o` and `%O` specifiers for printing objects. [#14558](#14558) PR-URL: #14811
Notable changes * **HTTP2** * Experimental support for the built-in `http2` has been added via the `--expose-http2` flag. [#14239](#14239) * **Inspector** * `require()` is available in the inspector console now. [#8837](#8837) * Multiple contexts, as created by the `vm` module, are supported now. [#14465](#14465) * **N-API** * New APIs for creating number values have been introduced. [#14573](#14573) * **Stream** * For `Duplex` streams, the high water mark option can now be set independently for the readable and the writable side. [#14636](#14636) * **Util** * `util.format` now supports the `%o` and `%O` specifiers for printing objects. [#14558](#14558) PR-URL: #14811
Notable changes * **HTTP2** * Experimental support for the built-in `http2` has been added via the `--expose-http2` flag. [#14239](#14239) * **Inspector** * `require()` is available in the inspector console now. [#8837](#8837) * Multiple contexts, as created by the `vm` module, are supported now. [#14465](#14465) * **N-API** * New APIs for creating number values have been introduced. [#14573](#14573) * **Stream** * For `Duplex` streams, the high water mark option can now be set independently for the readable and the writable side. [#14636](#14636) * **Util** * `util.format` now supports the `%o` and `%O` specifiers for printing objects. [#14558](#14558) PR-URL: #14811
Notable changes * **HTTP2** * Experimental support for the built-in `http2` has been added via the `--expose-http2` flag. [#14239](nodejs/node#14239) * **Inspector** * `require()` is available in the inspector console now. [#8837](nodejs/node#8837) * Multiple contexts, as created by the `vm` module, are supported now. [#14465](nodejs/node#14465) * **N-API** * New APIs for creating number values have been introduced. [#14573](nodejs/node#14573) * **Stream** * For `Duplex` streams, the high water mark option can now be set independently for the readable and the writable side. [#14636](nodejs/node#14636) * **Util** * `util.format` now supports the `%o` and `%O` specifiers for printing objects. [#14558](nodejs/node#14558) PR-URL: nodejs/node#14811
gibfahn
commented
Jan 15, 2018
Release team were +1 on backporting to v6.x. |




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: #14545
Checklist
make -j4 test(UNIX), orvcbuild test(Windows) passesAffected core subsystem(s)
util