Better formatting

This commit is contained in:
Gregory Schier
2024-02-02 13:37:44 -08:00
parent 6c69fff27d
commit fb817bc2d5
2 changed files with 15 additions and 4 deletions

View File

@@ -1,6 +1,7 @@
export function tryFormatJson(text: string): string {
export function tryFormatJson(text: string, pretty = true): string {
try {
return JSON.stringify(JSON.parse(text), null, 2);
if (pretty) return JSON.stringify(JSON.parse(text), null, 2);
else return JSON.stringify(JSON.parse(text));
} catch (_) {
return text;
}