(json: string)
| 2 | import chalk from "chalk"; |
| 3 | |
| 4 | function highlight(json: string): string { |
| 5 | return json |
| 6 | .replace(/("(?:\\.|[^"\\])*")\s*:/g, (_, key) => `${chalk.cyan(key)}:`) |
| 7 | .replace(/:\s*("(?:\\.|[^"\\])*")/g, (match, val) => match.replace(val, chalk.green(val))) |
| 8 | .replace(/:\s*(\d+(?:\.\d+)?)\b/g, (_, num) => `: ${chalk.yellow(num)}`) |
| 9 | .replace(/:\s*(true|false|null)\b/g, (_, lit) => `: ${chalk.magenta(lit)}`); |
| 10 | } |
| 11 | |
| 12 | function elapsed(ms: number): string { |
| 13 | if (ms < 1000) return `${ms}ms`; |