diff options
author | 2023-08-17 20:56:52 -0700 | |
---|---|---|
committer | 2023-08-17 20:56:52 -0700 | |
commit | 6fd0043f6bf766cc488a88339059e8879fa07161 (patch) | |
tree | d5289bcaf0880a3bf1e2f0b1c681aff93188fe51 /src/js/builtins/UtilInspect.ts | |
parent | 0424fd8f6e7549ed779788006acdc97a8467e287 (diff) | |
download | bun-6fd0043f6bf766cc488a88339059e8879fa07161.tar.gz bun-6fd0043f6bf766cc488a88339059e8879fa07161.tar.zst bun-6fd0043f6bf766cc488a88339059e8879fa07161.zip |
Add `util.inspect.custom` support to `util.inspect/Bun.inspect/console.log` (#4194)
* start work on util.inspect.custom
* asdf
* finish util inspect custom inspect
* inspect
* fix tests
* revert
* tidy
* revert
* oops
* test
* fix issues
Diffstat (limited to 'src/js/builtins/UtilInspect.ts')
-rw-r--r-- | src/js/builtins/UtilInspect.ts | 17 |
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; +} |