Prettify json bytes in Web UI

This commit is contained in:
Hugo Fonseca
2021-12-14 00:39:55 +00:00
committed by GitHub
parent 980cdedcc4
commit 711ca8b5c8
19 changed files with 53 additions and 33 deletions

View File

@@ -102,3 +102,22 @@ export function percentage(numerator: number, denominator: number): string {
const perc = ((numerator / denominator) * 100).toFixed(2);
return `${perc} %`;
}
export function isJsonPayload(p: string) {
try {
JSON.parse(p);
} catch (error) {
return false;
}
return true;
}
export function prettifyPayload(p: string) {
if (isJsonPayload(p)) {
return JSON.stringify(JSON.parse(p), null, 2);
}
return p;
}