自定义 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 的颜色相关联的映射。
¥util.inspect.styles is a map associating a style name to a color from
util.inspect.colors.
默认的样式和相关的颜色为:
¥The default styles and associated colors are:
-
bigint:yellow -
boolean:yellow -
date:magenta -
module:underline -
name:(没有样式)¥
name: (no styling) -
null:bold -
number:yellow -
regexp:一种对字符类、组、断言和其他部分进行着色以提高可读性的方法。要自定义颜色,请更改colors属性。默认情况下,它设置为['red', 'green', 'yellow', 'cyan', 'magenta'],可根据需要进行调整。数组会根据 "depth" 进行重复迭代。¥
regexp: A method that colors character classes, groups, assertions, and other parts for improved readability. To customize the coloring, change thecolorsproperty. It is set to['red', 'green', 'yellow', 'cyan', 'magenta']by default and may be adjusted as needed. The array is repetitively iterated through depending on the "depth". -
special:cyan(例如,Proxies)¥
special:cyan(e.g.,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").