@dugongjs/cli
Version:
16 lines (15 loc) • 640 B
JavaScript
import chalk from "chalk";
import { Box, Text } from "ink";
import React from "react";
function colorizeJson(value) {
return JSON.stringify(value, null, 2)
.replace(/"([^"]+)":/g, chalk.cyan(`"$1":`)) // keys
.replace(/: "(.*?)"/g, (_, str) => `: ${chalk.green(`"${str}"`)}`) // strings
.replace(/: (\d+)/g, (_, num) => `: ${chalk.yellow(num)}`); // numbers
}
export const JSONViewer = (props) => {
const { data } = props;
return (React.createElement(Box, { flexDirection: "column" }, colorizeJson(data)
.split("\n")
.map((line, i) => (React.createElement(Text, { key: i }, line)))));
};