mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-28 12:11:53 +01:00
Format XML responses
This commit is contained in:
@@ -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;
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user