Skip to content
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

util: add tagOnly option to util.inspect #17140

Closed
wants to merge 1 commit into from

Conversation

devsnek
Copy link
Member

@devsnek devsnek commented Nov 19, 2017

Returns the inspected value without inspecting the keys/values of the
object.

I am requesting to add this feature mostly so that it can be used with console.table, but I'm sure people will use it for other things too.

Checklist
  • make -j4 test (UNIX), or vcbuild test (Windows) passes
  • tests and/or benchmarks are included
  • documentation is changed or added
  • commit message follows commit guidelines
Affected core subsystem(s)

util

@nodejs-github-bot nodejs-github-bot added the util Issues and PRs related to the built-in util module. label Nov 19, 2017
@Trott Trott added the semver-minor PRs that contain new features and should be released in the next minor version. label Nov 19, 2017
Trott
Trott previously requested changes Nov 19, 2017
Copy link
Member

@Trott Trott left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documentation correction needed, but other than that, looks OK to me. No opinion as to whether this should be exposed as proposed here or instead added to internal/util.js somehow. I think I'm in favor of exposing it, but I don't have a strong opinion.

doc/api/util.md Outdated
@@ -327,6 +327,8 @@ changes:
* `options` {Object}
* `showHidden` {boolean} If `true`, the `object`'s non-enumerable symbols and
properties will be included in the formatted result. Defaults to `false`.
* `showHidden` {boolean} If `true`, the `object`'s keys/values will be
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This should say showNone rather than showHidden I think?

@devsnek
Copy link
Member Author

devsnek commented Nov 19, 2017

i was originally going to throw it in internal but i couldn't think of a good way to split this up from util.inspect that didn't kill perf or require large amounts of duplication. I think its probably fine to just have the option.

Copy link
Contributor

@cjihrig cjihrig left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code looks OK to me. I don't really like the name showNone though. Perhaps something like tagsOnly or similar. Sorry for the bikeshed.

@devsnek
Copy link
Member Author

devsnek commented Nov 20, 2017

@cjihrig no problem! i don't really like showNone either 😄

@Trott Trott dismissed their stale review November 20, 2017 22:43

requested change has been implemented

@devsnek
Copy link
Member Author

devsnek commented Nov 21, 2017

i like tagOnly and flat, if people have other ideas please let me know

@devsnek devsnek changed the title util: add showNone option to util.inspect util: add tagOnly option to util.inspect Nov 24, 2017
doc/api/util.md Outdated
@@ -327,6 +327,8 @@ changes:
* `options` {Object}
* `showHidden` {boolean} If `true`, the `object`'s non-enumerable symbols and
properties will be included in the formatted result. Defaults to `false`.
* `tagOnly` {boolean} If `true`, only the tag of `object` will be shown,
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there may need to be additional detail about what is meant by "tag" here.

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i was thinking the same thing, but i wasn't sure what to write, so i just hoped the example below would be enough

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If `true`, only the object type (tag) will be shown, ignoring all keys and values. Printing is like the same object being empty. Defaults to `false`.

Something like that?

@BridgeAR
Copy link
Member

@devsnek what about calling it metaOnly? And about exposing it - I personally do not know any use cases besides the one you mentioned and I am not sure if it makes sense therefore but I do not have a strong opinion on it.

@devsnek
Copy link
Member Author

devsnek commented Dec 10, 2017

I can't think of a good way to not expose it

@BridgeAR
Copy link
Member

@devsnek you are right, I meant not documenting it. There is another option not documented at the moment, so it would work similar.

@devsnek
Copy link
Member Author

devsnek commented Dec 10, 2017

@BridgeAR i have no qualms with that, shall i remove the docs?

@devsnek devsnek force-pushed the feature/util-inspect-shownone branch from 7e19899 to 8be2c63 Compare December 17, 2017 17:00
@devsnek
Copy link
Member Author

devsnek commented Dec 17, 2017

@BridgeAR @jasnell @Trott @cjihrig i removed the docs, it should be good to go now

@devsnek
Copy link
Member Author

devsnek commented Jan 12, 2018

i'm just gonna close this since something moderately similar can be achieved with -1 depth and the pr appears to be dead

@devsnek devsnek closed this Jan 12, 2018
@devsnek devsnek deleted the feature/util-inspect-shownone branch January 12, 2018 16:44
@BridgeAR
Copy link
Member

@devsnek I like the thought about the depth option! That is probably indeed a better way of doing this.

Thanks a lot for the PR anyway and I am sorry that I did not look into it earlier again!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
semver-minor PRs that contain new features and should be released in the next minor version. util Issues and PRs related to the built-in util module.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants