Little changes in json formatter. (#83)

Co-authored-by: Artur Kołecki <koleckiartur@icloud.com>
Reviewed-on: R11/release11-tools-web#83
This commit is contained in:
2023-02-28 14:08:26 +01:00
parent 4d7c0d6acd
commit d6c2c863eb
2 changed files with 20 additions and 9 deletions

View File

@@ -1,29 +1,39 @@
function formatAndValidateJson(errorElement) {
const input = document.querySelector('#jsonBlock');
const errorOutput = document.getElementById(errorElement);
const processInfo = document.getElementById(errorElement);
try {
const start = new Date();
const obj = JSON.parse(input.textContent);
input.innerHTML = JSON.stringify(obj, null, 2);
errorOutput.innerText = "";
processInfo.innerText = "";
hljs.highlightElement(input);
const end = new Date();
processInfo.innerHTML = "<b style='color: black'>Validation and formatting time:</b> <span style='color: green'>" + (end.getMilliseconds() - start.getMilliseconds()) + "ms</span>";
} catch (error) {
errorOutput.innerText = error;
processInfo.innerHTML = "<b style='color: red'>" + error + "</b>";
console.error("Error: ", error)
}
}
function minimizeJson(errorElement) {
const input = document.querySelector('#jsonBlock');
const errorOutput = document.getElementById(errorElement);
const processInfo = document.getElementById(errorElement);
try {
const start = new Date();
const obj = JSON.parse(input.textContent);
input.innerHTML = JSON.stringify(obj);
errorOutput.innerText = "";
processInfo.innerText = "";
hljs.highlightElement(input);
const end = new Date();
processInfo.innerHTML = "<b style='color: black'>Validation and formatting time:</b> <span style='color: green'>" + (end.getMilliseconds() - start.getMilliseconds()) + "ms</span>";
} catch (error) {
errorOutput.innerText = error;
processInfo.innerHTML = "<b style='color: red'>" + error + "</b>";
console.error("Error: ", error)
}
}