Reformated jsonFormatter.js
This commit is contained in:
@@ -11,11 +11,11 @@ const mergeHTMLPlugin = (function () {
|
|||||||
*/
|
*/
|
||||||
function escapeHTML(value) {
|
function escapeHTML(value) {
|
||||||
return value
|
return value
|
||||||
.replace(/&/g, '&')
|
.replace(/&/g, '&')
|
||||||
.replace(/</g, '<')
|
.replace(/</g, '<')
|
||||||
.replace(/>/g, '>')
|
.replace(/>/g, '>')
|
||||||
.replace(/"/g, '"')
|
.replace(/"/g, '"')
|
||||||
.replace(/'/g, ''');
|
.replace(/'/g, ''');
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -161,6 +161,78 @@ const mergeHTMLPlugin = (function () {
|
|||||||
|
|
||||||
}());
|
}());
|
||||||
|
|
||||||
|
function formatAndValidateJson(errorElement) {
|
||||||
|
const input = document.querySelector('#jsonBlock');
|
||||||
|
const processInfo = document.getElementById(errorElement);
|
||||||
|
|
||||||
|
const address = window.location.protocol + "//" + window.location.hostname + ":" + 8081 + "/json/formatting"
|
||||||
|
|
||||||
|
fetch(address, {
|
||||||
|
method: 'POST',
|
||||||
|
body: input.textContent
|
||||||
|
})
|
||||||
|
.then(async (response) => {
|
||||||
|
const promise = response.json();
|
||||||
|
if (!response.ok) {
|
||||||
|
throw Error(await promise);
|
||||||
|
}
|
||||||
|
|
||||||
|
return promise;
|
||||||
|
})
|
||||||
|
.then((data) => {
|
||||||
|
input.innerText = data.data;
|
||||||
|
processInfo.innerText = "";
|
||||||
|
hljs.highlightElement(input);
|
||||||
|
|
||||||
|
processInfo.innerHTML = "<b style='color: green'>Computed in </b> <span style='color: green'>" + data.time + "ms</span>";
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
processInfo.innerHTML = "<b style='color: red'>" + error.data + "</b>";
|
||||||
|
console.error('Error:', error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function minimizeJson(errorElement) {
|
||||||
|
const input = document.querySelector('#jsonBlock');
|
||||||
|
const processInfo = document.getElementById(errorElement);
|
||||||
|
|
||||||
|
const address = window.location.protocol + "//" + window.location.hostname + ":" + 8081 + "/json/minimize"
|
||||||
|
|
||||||
|
fetch(address, {
|
||||||
|
method: 'POST',
|
||||||
|
body: input.textContent
|
||||||
|
})
|
||||||
|
.then(async (response) => {
|
||||||
|
const promise = response.json();
|
||||||
|
if (!response.ok) {
|
||||||
|
throw Error(await promise);
|
||||||
|
}
|
||||||
|
|
||||||
|
return promise;
|
||||||
|
})
|
||||||
|
.then((data) => {
|
||||||
|
input.innerText = data.data;
|
||||||
|
processInfo.innerText = "";
|
||||||
|
hljs.highlightElement(input);
|
||||||
|
|
||||||
|
processInfo.innerHTML = "<b style='color: green'>Computed in </b> <span style='color: green'>" + data.time + "ms</span>";
|
||||||
|
})
|
||||||
|
.catch((error) => {
|
||||||
|
processInfo.innerHTML = "<b style='color: red'>" + error.data + "</b>";
|
||||||
|
console.error('Error:', error);
|
||||||
|
});
|
||||||
|
}
|
||||||
|
|
||||||
|
function clearJsonData() {
|
||||||
|
const input = document.querySelector('#jsonBlock');
|
||||||
|
input.textContent = "";
|
||||||
|
}
|
||||||
|
|
||||||
|
function insertDefaultJson() {
|
||||||
|
const input = document.querySelector('#jsonBlock');
|
||||||
|
input.textContent = "{\"enter\": \"your\", \"json\": \"here\"}";
|
||||||
|
hljs.highlightElement(input);
|
||||||
|
}
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* This function is executed after the page is loaded.
|
* This function is executed after the page is loaded.
|
||||||
@@ -176,75 +248,3 @@ function init() {
|
|||||||
hljs.addPlugin(mergeHTMLPlugin);
|
hljs.addPlugin(mergeHTMLPlugin);
|
||||||
}
|
}
|
||||||
|
|
||||||
function formatAndValidateJson(errorElement) {
|
|
||||||
const input = document.querySelector('#jsonBlock');
|
|
||||||
const processInfo = document.getElementById(errorElement);
|
|
||||||
|
|
||||||
const address = window.location.protocol + "//" + window.location.hostname + ":" + 8081 + "/json/formatting"
|
|
||||||
|
|
||||||
fetch(address, {
|
|
||||||
method: 'POST',
|
|
||||||
body: input.textContent
|
|
||||||
})
|
|
||||||
.then(async (response) => {
|
|
||||||
const promise = response.json();
|
|
||||||
if (!response.ok) {
|
|
||||||
throw Error(await promise);
|
|
||||||
}
|
|
||||||
|
|
||||||
return promise;
|
|
||||||
})
|
|
||||||
.then((data) => {
|
|
||||||
input.innerText = data.data;
|
|
||||||
processInfo.innerText = "";
|
|
||||||
hljs.highlightElement(input);
|
|
||||||
|
|
||||||
processInfo.innerHTML = "<b style='color: green'>Computed in </b> <span style='color: green'>" + data.time + "ms</span>";
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
processInfo.innerHTML = "<b style='color: red'>" + error.data + "</b>";
|
|
||||||
console.error('Error:', error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function minimizeJson(errorElement) {
|
|
||||||
const input = document.querySelector('#jsonBlock');
|
|
||||||
const processInfo = document.getElementById(errorElement);
|
|
||||||
|
|
||||||
const address = window.location.protocol + "//" + window.location.hostname + ":" + 8081 + "/json/minimize"
|
|
||||||
|
|
||||||
fetch(address, {
|
|
||||||
method: 'POST',
|
|
||||||
body: input.textContent
|
|
||||||
})
|
|
||||||
.then(async (response) => {
|
|
||||||
const promise = response.json();
|
|
||||||
if (!response.ok) {
|
|
||||||
throw Error(await promise);
|
|
||||||
}
|
|
||||||
|
|
||||||
return promise;
|
|
||||||
})
|
|
||||||
.then((data) => {
|
|
||||||
input.innerText = data.data;
|
|
||||||
processInfo.innerText = "";
|
|
||||||
hljs.highlightElement(input);
|
|
||||||
|
|
||||||
processInfo.innerHTML = "<b style='color: green'>Computed in </b> <span style='color: green'>" + data.time + "ms</span>";
|
|
||||||
})
|
|
||||||
.catch((error) => {
|
|
||||||
processInfo.innerHTML = "<b style='color: red'>" + error.data + "</b>";
|
|
||||||
console.error('Error:', error);
|
|
||||||
});
|
|
||||||
}
|
|
||||||
|
|
||||||
function clearJsonData() {
|
|
||||||
const input = document.querySelector('#jsonBlock');
|
|
||||||
input.textContent = "";
|
|
||||||
}
|
|
||||||
|
|
||||||
function insertDefaultJson() {
|
|
||||||
const input = document.querySelector('#jsonBlock');
|
|
||||||
input.textContent = "{\"enter\": \"your\", \"json\": \"here\"}";
|
|
||||||
hljs.highlightElement(input);
|
|
||||||
}
|
|
||||||
Reference in New Issue
Block a user