Custom JSON formatter that works with template syntax (#128)

This commit is contained in:
Gregory Schier
2024-10-21 22:17:14 +00:00
committed by GitHub
parent aa7f18a16f
commit e216214085
17 changed files with 414 additions and 117 deletions

View File

@@ -1,20 +1,14 @@
import xmlFormat from 'xml-formatter';
import { invokeCmd } from './tauri';
const INDENT = ' ';
export function tryFormatJson(text: string, pretty = true): string {
export async function tryFormatJson(text: string): Promise<string> {
if (text === '') return text;
try {
if (pretty) return JSON.stringify(JSON.parse(text), null, INDENT);
else return JSON.stringify(JSON.parse(text));
// eslint-disable-next-line @typescript-eslint/no-unused-vars
} catch (err) {
return text;
}
return invokeCmd('cmd_format_json', { text });
}
export function tryFormatXml(text: string): string {
export async function tryFormatXml(text: string): Promise<string> {
if (text === '') return text;
try {

View File

@@ -28,6 +28,7 @@ type TauriCmd =
| 'cmd_duplicate_http_request'
| 'cmd_export_data'
| 'cmd_filter_response'
| 'cmd_format_json'
| 'cmd_get_cookie_jar'
| 'cmd_get_environment'
| 'cmd_get_folder'