Everything in messages now

This commit is contained in:
Gregory Schier
2024-02-22 19:51:30 -08:00
parent e6c0317b37
commit f2955c26c1
10 changed files with 231 additions and 205 deletions

View File

@@ -1,8 +1,12 @@
import xmlFormat from 'xml-formatter';
const INDENT = ' ';
export function tryFormatJson(text: string, pretty = true): string {
if (text === '') return text;
try {
if (pretty) return JSON.stringify(JSON.parse(text), null, 2);
if (pretty) return JSON.stringify(JSON.parse(text), null, INDENT);
else return JSON.stringify(JSON.parse(text));
} catch (_) {
return text;
@@ -10,8 +14,10 @@ export function tryFormatJson(text: string, pretty = true): string {
}
export function tryFormatXml(text: string): string {
if (text === '') return text;
try {
return xmlFormat(text, { throwOnFailure: true, strictMode: false });
return xmlFormat(text, { throwOnFailure: true, strictMode: false, indentation: INDENT });
} catch (_) {
return text;
}