Format XML responses

This commit is contained in:
Gregory Schier committed 2024-02-22 01:00:02 -08:00
1 parent ca4d9b1ad6
commit 321b013ce6
5 files changed
+40 -6

No files matched your search

+10
View File
@@ -1,3 +1,5 @@
import xmlFormat from 'xml-formatter';
export function tryFormatJson(text: string, pretty = true): string {
try {
if (pretty) return JSON.stringify(JSON.parse(text), null, 2);
@@ -6,3 +8,11 @@ export function tryFormatJson(text: string, pretty = true): string {
return text;
}
}
export function tryFormatXml(text: string): string {
try {
return xmlFormat(text, { throwOnFailure: true, strictMode: false });
} catch (_) {
return text;
}
}