自定义 util.inspect 颜色


🌐 Customizing util.inspect colors

util.inspect 的颜色输出(如果启用)可以通过 util.inspect.stylesutil.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
  • booleanyellow
  • datemagenta
  • moduleunderline
  • name:(无样式)
  • nullbold
  • number: yellow
  • regexp: red
  • specialcyan(例如,Proxies
  • stringgreen
  • symbolgreen
  • undefinedgrey

颜色样式使用 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").