Skip to content

Support util.inspect.custom as a public symbol #20821

@chocolateboy

Description

@chocolateboy
  • Version: v10.1.0
  • Platform: Linux (Arch)
  • Subsystem: util

Please consider supporting util.inspect.custom as a public/global symbol either by:

  1. changing util.inspect.custom from a private symbol (e.g. Symbol('util.inspect.custom')) to a public symbol (e.g. Symbol.for('util.inspect.custom'))

or:

  1. accepting a public symbol as an alternative to the private symbol, just as "inspect" is currently accepted as a (deprecated) fallback for the symbol

Changing it from a string to a symbol was a great idea 🎉 and it's a perfect use case for a symbol, but, as mentioned here, making it private makes it painful to write code that both a) provides an inspect hook if it's loaded in node and b) works seamlessly in the browser if it's not.

A workaround has been implemented as an NPM module, inspect-custom-symbol (cc @mafintosh), which uses the browser field in its package.json to provide a substitute symbol without pulling in the util library in bundlers such as Browserify and Webpack. It's much better than trying to work around this with a tower of late-bound typeof util.inspect.custom checks, but it doesn't fix the underlying issue and it's not ideal:

  • it doesn't work in all situations/environments
  • it requires an extra dependency
  • most people with this dilemma won't be aware of it

Metadata

Metadata

Assignees

No one assigned

    Labels

    feature requestIssues that request new features to be added to Node.js.utilIssues and PRs related to the built-in util module.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions