自定义 util.inspect 颜色


🌐 Customizing util.inspect colors

util.inspect 的颜色输出(如果启用)可以通过 util.inspect.styles 和 util.inspect.colors 属性在全局范围内自定义。

🌐 Color output (if enabled) of util.inspect is customizable globally via the util.inspect.styles and util.inspect.colors properties.

util.inspect.styles 是一个将样式名称与 util.inspect.colors 中的颜色关联的映射。

默认的样式和相关的颜色为:

🌐 The default styles and associated colors are:

  • bigint:yellow
  • boolean:yellow
  • date:magenta
  • module:underline
  • name:(无样式)
  • null:bold
  • number:yellow
  • regexp:red
  • special:cyan(例如,Proxies)
  • string:green
  • symbol:green
  • undefined:grey

颜色样式使用 ANSI 控制码,某些终端可能不支持。要验证颜色支持,请使用 tty.hasColors()。

🌐 Color styling uses ANSI control codes that may not be supported on all terminals. To verify color support use tty.hasColors().

预定义的控制代码列在下面(分为“修饰符”、“前景色”和“背景色”)。

🌐 Predefined control codes are listed below (grouped as "Modifiers", "Foreground colors", and "Background colors").