Repository navigation
Expand file tree
/
Copy pathbrowser-test.html
More file actions
195 lines (162 loc) · 5.23 KB
/
Copy pathbrowser-test.html
File metadata and controls
195 lines (162 loc) · 5.23 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
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>TONL Browser Test</title>
<style>
body {
font-family: monospace;
max-width: 1200px;
margin: 0 auto;
padding: 20px;
background: #1e1e1e;
color: #d4d4d4;
}
h1 { color: #4ec9b0; }
h2 { color: #9cdcfe; margin-top: 30px; }
pre {
background: #2d2d2d;
padding: 15px;
border-radius: 5px;
overflow-x: auto;
}
.success { color: #4ec9b0; }
.error { color: #f48771; }
button {
background: #0e639c;
color: white;
border: none;
padding: 10px 20px;
border-radius: 5px;
cursor: pointer;
font-size: 14px;
margin: 10px 5px;
}
button:hover { background: #1177bb; }
#output { margin-top: 20px; }
</style>
</head>
<body>
<h1>🚀 TONL Browser Test (v0.5.0)</h1>
<p>Testing TONL in the browser with all three bundle formats.</p>
<h2>Test 1: ESM Bundle</h2>
<button onclick="testESM()">Run ESM Test</button>
<pre id="esm-output">Click button to test...</pre>
<h2>Test 2: UMD Bundle</h2>
<button onclick="testUMD()">Run UMD Test</button>
<pre id="umd-output">Click button to test...</pre>
<h2>Test 3: IIFE Bundle</h2>
<button onclick="testIIFE()">Run IIFE Test</button>
<pre id="iife-output">Click button to test...</pre>
<!-- IIFE Bundle (loads immediately) -->
<script src="../dist/browser/tonl.iife.js"></script>
<!-- ESM Test -->
<script type="module">
import { encodeTONL, decodeTONL, encodeSmart } from '../dist/browser/tonl.esm.js';
window.testESM = function() {
const output = document.getElementById('esm-output');
try {
const data = {
users: [
{ id: 1, name: 'Alice', role: 'admin' },
{ id: 2, name: 'Bob', role: 'user' }
],
count: 2
};
// Encode
const tonl = encodeTONL(data, { delimiter: ',' });
// Decode
const decoded = decodeTONL(tonl);
// Verify round-trip
const match = JSON.stringify(data) === JSON.stringify(decoded);
output.innerHTML = `<span class="success">✅ ESM Test Passed!</span>
Input Data:
${JSON.stringify(data, null, 2)}
TONL Output:
${tonl}
Round-trip Match: ${match ? '<span class="success">✅ YES</span>' : '<span class="error">❌ NO</span>'}
Bundle Format: ESM (6.32 KB gzipped)`;
} catch (error) {
output.innerHTML = `<span class="error">❌ ESM Test Failed: ${error.message}</span>`;
}
};
</script>
<!-- UMD Test -->
<script>
// UMD loaded via require or global
function loadUMD() {
return new Promise((resolve) => {
const script = document.createElement('script');
script.src = '../dist/browser/tonl.umd.js';
script.onload = () => resolve(window.TONL);
document.head.appendChild(script);
});
}
window.testUMD = async function() {
const output = document.getElementById('umd-output');
try {
// UMD might already be loaded or we load it
const TONL = window.TONL || await loadUMD();
const data = {
config: {
host: 'localhost',
port: 3000,
enabled: true
}
};
const tonl = TONL.encodeTONL(data);
const decoded = TONL.decodeTONL(tonl);
const match = JSON.stringify(data) === JSON.stringify(decoded);
output.innerHTML = `<span class="success">✅ UMD Test Passed!</span>
Input Data:
${JSON.stringify(data, null, 2)}
TONL Output:
${tonl}
Round-trip Match: ${match ? '<span class="success">✅ YES</span>' : '<span class="error">❌ NO</span>'}
Bundle Format: UMD (4.53 KB gzipped)`;
} catch (error) {
output.innerHTML = `<span class="error">❌ UMD Test Failed: ${error.message}</span>`;
}
};
</script>
<!-- IIFE Test -->
<script>
window.testIIFE = function() {
const output = document.getElementById('iife-output');
try {
// IIFE creates global TONL
if (!window.TONL) {
throw new Error('TONL global not found');
}
const data = {
products: [
{ id: 101, name: 'Widget', price: 29.99 },
{ id: 102, name: 'Gadget', price: 49.99 }
]
};
const tonl = TONL.encodeSmart(data);
const decoded = TONL.decodeTONL(tonl);
const match = JSON.stringify(data) === JSON.stringify(decoded);
// Calculate compression
const jsonSize = JSON.stringify(data).length;
const tonlSize = tonl.length;
const compression = ((1 - tonlSize / jsonSize) * 100).toFixed(1);
output.innerHTML = `<span class="success">✅ IIFE Test Passed!</span>
Input Data:
${JSON.stringify(data, null, 2)}
TONL Output (Smart Encoding):
${tonl}
Round-trip Match: ${match ? '<span class="success">✅ YES</span>' : '<span class="error">❌ NO</span>'}
Stats:
- JSON Size: ${jsonSize} bytes
- TONL Size: ${tonlSize} bytes
- Compression: ${compression}%
Bundle Format: IIFE (4.45 KB gzipped)`;
} catch (error) {
output.innerHTML = `<span class="error">❌ IIFE Test Failed: ${error.message}</span>`;
}
};
</script>
</body>
</html>