aboutsummaryrefslogtreecommitdiff
path: root/src/js/builtins/UtilInspect.ts
diff options
context:
space:
mode:
Diffstat (limited to 'src/js/builtins/UtilInspect.ts')
-rw-r--r--src/js/builtins/UtilInspect.ts17
1 files changed, 17 insertions, 0 deletions
diff --git a/src/js/builtins/UtilInspect.ts b/src/js/builtins/UtilInspect.ts
new file mode 100644
index 000000000..586f03b57
--- /dev/null
+++ b/src/js/builtins/UtilInspect.ts
@@ -0,0 +1,17 @@
+type Inspect = typeof import("util").inspect;
+
+// This is passed to [util.inspect.custom](..., { stylize }) to help users colorize parts.
+export function getStylizeWithColor(inspect: Inspect) {
+ return function stylizeWithColor(str: string, styleType: string) {
+ const style = inspect.styles[styleType];
+ if (style !== undefined) {
+ const color = inspect.colors[style];
+ if (color !== undefined) return `\u001b[${color[0]}m${str}\u001b[${color[1]}m`;
+ }
+ return str;
+ };
+}
+
+export function stylizeWithNoColor(str: string) {
+ return str;
+}