-
Notifications
You must be signed in to change notification settings - Fork 6
Expand file tree
/
Copy pathoutput.js
More file actions
77 lines (67 loc) · 1.67 KB
/
output.js
File metadata and controls
77 lines (67 loc) · 1.67 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
function createOutputSection() {
return `
<div class="output-container">
<h3>Output</h3>
<div id="output">
<pre id="errorOutput"></pre>
<pre id="standardOutput">Nothing yet</pre>
</div>
</div>
`;
}
function formatOutput(data) {
if (typeof data === 'string') {
try {
// Try to parse as JSON
return JSON.stringify(JSON.parse(data), null, 2);
} catch (e) {
// If not JSON, use as string
return data;
}
} else {
return JSON.stringify(data, null, 2);
}
}
function displayOutput(output) {
const target = document.querySelector('#standardOutput');
if (!target) return;
target.textContent = formatOutput(output);
}
function clearOutput() {
const target = document.querySelector('#standardOutput');
target.innerHTML = '';
}
function displayError(message) {
const target = document.querySelector('#errorOutput');
if (!target) return;
target.textContent = message;
target.style.display = 'block';
}
function clearError() {
const target = document.querySelector('#errorOutput');
if (target) {
target.style.display = 'none';
target.innerHTML = '';
}
}
function initializeOutput() {
const outputContainer = document.querySelector('.output-container');
if (outputContainer) {
outputContainer.outerHTML = createOutputSection();
}
const standardOutput = document.getElementById('standardOutput');
if (standardOutput) {
const initialJSON = standardOutput.textContent;
if (initialJSON.trim()) {
standardOutput.textContent = initialJSON;
}
}
}
export {
createOutputSection,
displayOutput,
displayError,
clearError,
clearOutput,
initializeOutput,
};