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
|
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>cfg</title>
<script src="https://cdn.tailwindcss.com"></script>
</head>
<body class="bg-gray-100">
<div class="flex h-screen">
<div class="flex-1 flex flex-col p-4">
<h2 class="text-2xl font-bold mb-4">Input</h2>
<select id="from" class="w-full mb-2 p-2 border rounded">
<option value="json">json(c)</option>
<option value="jsonnet">jsonnet</option>
<option value="yaml">yaml</option>
<option value="toml">toml</option>
<option value="nix">nix</option>
<option value="dhall">dhall</option>
<option value="kdl">kdl</option>
</select>
<textarea id="input" class="flex-1 p-2 border rounded" placeholder="Paste your config here..."></textarea>
</div>
<div class="flex-1 flex flex-col p-4">
<h2 class="text-2xl font-bold mb-4">Output</h2>
<select id="to" class="w-full mb-2 p-2 border rounded">
<option value="json">json</option>
<option value="yaml">yaml</option>
<option value="toml">toml</option>
<option value="nix">nix</option>
<option value="kdl">kdl</option>
</select>
<textarea id="output" class="flex-1 p-2 border rounded" placeholder="Converted output will appear here..." readonly></textarea>
</div>
</div>
<script>
const $inputFormat = document.getElementById('from');
const $outputFormat = document.getElementById('to');
const $inputText = document.getElementById('input');
const $outputText = document.getElementById('output');
$inputFormat.addEventListener("input", convert);
$outputFormat.addEventListener("input", convert);
$inputText.addEventListener("input", convert);
function convert() {
fetch('/convert', {
method: 'POST',
headers: {
'Content-Type': 'application/json',
},
body: JSON.stringify({
from: $inputFormat.value,
to: $outputFormat.value,
input: $inputText.value,
}),
})
.then(response => response.text())
.then(data => {
$outputText.value = data;
})
.catch(error => {
console.error('Error:', error);
$outputText.value = 'An error occurred during conversion.';
});
}
</script>
</body>
</html>
|