aboutsummaryrefslogtreecommitdiff
path: root/src/js/builtins/UtilInspect.ts
blob: 586f03b5783bf195bf901a3134bcf90917aa3f6f (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
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;
}