mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-03-18 07:24:07 +01:00
19 lines
446 B
TypeScript
19 lines
446 B
TypeScript
import xmlFormat from 'xml-formatter';
|
|
|
|
export function tryFormatJson(text: string, pretty = true): string {
|
|
try {
|
|
if (pretty) return JSON.stringify(JSON.parse(text), null, 2);
|
|
else return JSON.stringify(JSON.parse(text));
|
|
} catch (_) {
|
|
return text;
|
|
}
|
|
}
|
|
|
|
export function tryFormatXml(text: string): string {
|
|
try {
|
|
return xmlFormat(text, { throwOnFailure: true, strictMode: false });
|
|
} catch (_) {
|
|
return text;
|
|
}
|
|
}
|