mirror of
https://github.com/mountain-loop/yaak.git
synced 2026-04-23 09:08:32 +02:00
Everything in messages now
This commit is contained in:
@@ -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;
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user