-
-
Notifications
You must be signed in to change notification settings - Fork 25
Expand file tree
/
Copy pathstring-transformer.html
More file actions
420 lines (375 loc) · 21.5 KB
/
string-transformer.html
File metadata and controls
420 lines (375 loc) · 21.5 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
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="icon" type="image/png" href="images/logo.png">
<link rel="apple-touch-icon" href="images/logo.png">
<title>String Transformer - Developer Toolkit | DevDunia</title>
<meta name="description" content="Transform strings between different formats and cases. Free online string transformer tool for developers.">
<script src="https://cdn.tailwindcss.com"></script>
<style>
body {
background: linear-gradient(135deg, #0f172a 0%, #1e293b 50%, #0f172a 100%);
}
</style>
</head>
<body class="h-screen lg:ml-72">
<!-- Background: Consistent Subtle Dark Gradient -->
<div class="fixed inset-0 -z-10 bg-gradient-to-br from-gray-900 via-slate-900 to-gray-900"></div>
<!-- Main Container -->
<div class="main-content">
<div class="relative z-10 container mx-auto px-4 pt-16 pb-24 sm:px-6 lg:px-8">
<!-- Page Header -->
<div class="text-center mb-12">
<h1 class="text-3xl sm:text-4xl font-bold mb-4 tracking-tight
text-transparent bg-clip-text bg-gradient-to-r from-blue-400 to-cyan-500">
String Transformer
</h1>
<p class="text-lg text-gray-400 max-w-2xl mx-auto">
Transform strings between different formats and cases.
</p>
</div>
<!-- Tool Container -->
<div class="max-w-4xl mx-auto">
<div class="bg-slate-800/70 backdrop-blur-md rounded-lg shadow-lg border border-slate-700/60 p-6">
<!-- Input Section -->
<div class="mb-6">
<label for="string-input" class="block text-sm font-medium text-gray-300 mb-2">
Input String
</label>
<textarea
id="string-input"
rows="4"
class="w-full px-4 py-3 bg-slate-700/50 border border-slate-600 rounded-lg text-gray-200 placeholder-gray-400 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent resize-none font-mono text-sm"
placeholder="Enter text to transform..."
></textarea>
</div>
<!-- Transformation Options -->
<div class="mb-6">
<label class="block text-sm font-medium text-gray-300 mb-3">Transformations</label>
<div class="grid grid-cols-1 md:grid-cols-2 lg:grid-cols-3 gap-3">
<button class="transform-btn px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white text-sm rounded-lg transition-colors duration-200" data-transform="uppercase">
UPPERCASE
</button>
<button class="transform-btn px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white text-sm rounded-lg transition-colors duration-200" data-transform="lowercase">
lowercase
</button>
<button class="transform-btn px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white text-sm rounded-lg transition-colors duration-200" data-transform="capitalize">
Capitalize
</button>
<button class="transform-btn px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white text-sm rounded-lg transition-colors duration-200" data-transform="title-case">
Title Case
</button>
<button class="transform-btn px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white text-sm rounded-lg transition-colors duration-200" data-transform="camel-case">
camelCase
</button>
<button class="transform-btn px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white text-sm rounded-lg transition-colors duration-200" data-transform="pascal-case">
PascalCase
</button>
<button class="transform-btn px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white text-sm rounded-lg transition-colors duration-200" data-transform="kebab-case">
kebab-case
</button>
<button class="transform-btn px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white text-sm rounded-lg transition-colors duration-200" data-transform="snake-case">
snake_case
</button>
<button class="transform-btn px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white text-sm rounded-lg transition-colors duration-200" data-transform="constant-case">
CONSTANT_CASE
</button>
<button class="transform-btn px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white text-sm rounded-lg transition-colors duration-200" data-transform="reverse">
Reverse
</button>
<button class="transform-btn px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white text-sm rounded-lg transition-colors duration-200" data-transform="slug">
slug
</button>
<button class="transform-btn px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white text-sm rounded-lg transition-colors duration-200" data-transform="remove-spaces">
Remove Spaces
</button>
<button class="transform-btn px-4 py-2 bg-blue-600 hover:bg-blue-700 text-white text-sm rounded-lg transition-colors duration-200" data-transform="frequency-counter">
Frequency Counter
</button>
</div>
</div>
<!-- Action Buttons -->
<div class="flex flex-wrap gap-3 mb-6">
<button id="clear-btn" class="px-6 py-3 bg-slate-600 hover:bg-slate-700 text-white font-medium rounded-lg transition-colors duration-200 flex items-center space-x-2">
<svg class="w-5 h-5" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M19 7l-.867 12.142A2 2 0 0116.138 21H7.862a2 2 0 01-1.995-1.858L5 7m5 4v6m4-6v6m1-10V4a1 1 0 00-1-1h-4a1 1 0 00-1 1v3M4 7h16"></path>
</svg>
<span>Clear All</span>
</button>
</div>
<!-- Output Section -->
<div id="output-section" class="hidden">
<div class="flex items-center justify-between mb-2">
<label for="string-output" class="text-sm font-medium text-gray-300">
Transformed Output
</label>
<button id="copy-btn" class="px-3 py-1 bg-slate-600 hover:bg-slate-700 text-white text-sm rounded transition-colors duration-200 flex items-center space-x-1">
<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24">
<path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M8 16H6a2 2 0 01-2-2V6a2 2 0 012-2h8a2 2 0 012 2v8a2 2 0 01-2 2h-2m-6-4l2 2m0 0l2-2m-2 2V10"></path>
</svg>
<span>Copy</span>
</button>
</div>
<!-- Text Output (default) -->
<div id="text-output-container" class="relative">
<textarea
id="string-output"
rows="4"
class="w-full px-4 py-3 bg-slate-700/50 border border-slate-600 rounded-lg text-gray-200 focus:outline-none focus:ring-2 focus:ring-blue-500 focus:border-transparent resize-none font-mono text-sm"
readonly
></textarea>
</div>
<!-- Table Output (for frequency counter) -->
<div id="table-output-container" class="hidden">
<div class="bg-slate-700/50 border border-slate-600 rounded-lg overflow-hidden">
<div class="overflow-x-auto">
<table id="frequency-table" class="w-full text-sm">
<thead class="bg-slate-600/50">
<tr>
<th class="text-left py-3 px-4 text-gray-300 font-medium">Character</th>
<th class="text-center py-3 px-4 text-gray-300 font-medium">Count</th>
<th class="text-center py-3 px-4 text-gray-300 font-medium">Percentage</th>
</tr>
</thead>
<tbody id="frequency-tbody" class="divide-y divide-slate-600">
<!-- Frequency data will be populated here -->
</tbody>
</table>
</div>
<div id="frequency-summary" class="px-4 py-3 bg-slate-600/30 border-t border-slate-600 text-xs text-gray-400">
<!-- Summary will be populated here -->
</div>
</div>
</div>
</div>
<!-- String Statistics -->
<div id="stats" class="hidden mt-6 grid grid-cols-1 md:grid-cols-4 gap-4">
<div class="bg-slate-700/50 p-3 rounded-lg">
<h4 class="text-sm font-medium text-gray-300 mb-1">Characters</h4>
<p id="char-count" class="text-blue-400 font-mono text-sm"></p>
</div>
<div class="bg-slate-700/50 p-3 rounded-lg">
<h4 class="text-sm font-medium text-gray-300 mb-1">Words</h4>
<p id="word-count" class="text-green-400 font-mono text-sm"></p>
</div>
<div class="bg-slate-700/50 p-3 rounded-lg">
<h4 class="text-sm font-medium text-gray-300 mb-1">Lines</h4>
<p id="line-count" class="text-purple-400 font-mono text-sm"></p>
</div>
<div class="bg-slate-700/50 p-3 rounded-lg">
<h4 class="text-sm font-medium text-gray-300 mb-1">Size</h4>
<p id="size-info" class="text-orange-400 font-mono text-sm"></p>
</div>
</div>
</div>
</div>
</div>
<!-- Footer include -->
<div id="footer"></div>
<script>
fetch("footer.html")
.then(response => response.text())
.then(data => {
document.getElementById("footer").innerHTML = data;
})
.catch(err => console.error("Failed to load footer:", err));
</script>
<script>
document.addEventListener('DOMContentLoaded', function() {
const stringInput = document.getElementById('string-input');
const stringOutput = document.getElementById('string-output');
const clearBtn = document.getElementById('clear-btn');
const copyBtn = document.getElementById('copy-btn');
const outputSection = document.getElementById('output-section');
const stats = document.getElementById('stats');
const charCount = document.getElementById('char-count');
const wordCount = document.getElementById('word-count');
const lineCount = document.getElementById('line-count');
const sizeInfo = document.getElementById('size-info');
// Transform buttons
document.querySelectorAll('.transform-btn').forEach(btn => {
btn.addEventListener('click', function() {
const transform = this.getAttribute('data-transform');
const input = stringInput.value.trim();
if (!input) {
alert('Please enter some text to transform');
return;
}
const transformed = transformString(input, transform);
stringOutput.value = transformed;
showOutput();
updateStats(transformed);
});
});
// Clear all
clearBtn.addEventListener('click', function() {
stringInput.value = '';
hideOutput();
});
// Copy output
copyBtn.addEventListener('click', function() {
stringOutput.select();
document.execCommand('copy');
// Visual feedback
const originalText = copyBtn.innerHTML;
copyBtn.innerHTML = '<svg class="w-4 h-4" fill="none" stroke="currentColor" viewBox="0 0 24 24"><path stroke-linecap="round" stroke-linejoin="round" stroke-width="2" d="M5 13l4 4L19 7"></path></svg><span>Copied!</span>';
copyBtn.classList.add('bg-green-600');
setTimeout(() => {
copyBtn.innerHTML = originalText;
copyBtn.classList.remove('bg-green-600');
}, 2000);
});
// Auto-resize input
stringInput.addEventListener('input', function() {
this.style.height = 'auto';
this.style.height = this.scrollHeight + 'px';
});
// Helper functions
function showOutput() {
outputSection.classList.remove('hidden');
stats.classList.remove('hidden');
}
function hideOutput() {
outputSection.classList.add('hidden');
stats.classList.add('hidden');
}
function transformString(input, transform) {
// Show/hide appropriate output container
const textContainer = document.getElementById('text-output-container');
const tableContainer = document.getElementById('table-output-container');
if (transform === 'frequency-counter') {
textContainer.classList.add('hidden');
tableContainer.classList.remove('hidden');
} else {
textContainer.classList.remove('hidden');
tableContainer.classList.add('hidden');
}
switch (transform) {
case 'uppercase':
return input.toUpperCase();
case 'lowercase':
return input.toLowerCase();
case 'capitalize':
return input.charAt(0).toUpperCase() + input.slice(1).toLowerCase();
case 'title-case':
return input.replace(/\w\S*/g, txt => txt.charAt(0).toUpperCase() + txt.substr(1).toLowerCase());
case 'camel-case':
return input.replace(/(?:^\w|[A-Z]|\b\w)/g, (word, index) => {
return index === 0 ? word.toLowerCase() : word.toUpperCase();
}).replace(/\s+/g, '');
case 'pascal-case':
return input.replace(/(?:^\w|[A-Z]|\b\w)/g, word => word.toUpperCase()).replace(/\s+/g, '');
case 'kebab-case':
return input.replace(/([a-z])([A-Z])/g, '$1-$2').replace(/[\s_]+/g, '-').toLowerCase();
case 'snake-case':
return input.replace(/([a-z])([A-Z])/g, '$1_$2').replace(/[\s-]+/g, '_').toLowerCase();
case 'constant-case':
return input.replace(/([a-z])([A-Z])/g, '$1_$2').replace(/[\s-]+/g, '_').toUpperCase();
case 'reverse':
return input.split('').reverse().join('');
case 'slug':
return input.toLowerCase()
.replace(/[^\w\s-]/g, '')
.replace(/[\s_-]+/g, '-')
.replace(/^-+|-+$/g, '');
case 'remove-spaces':
return input.replace(/\s+/g, '');
case 'frequency-counter':
return getCharacterFrequency(input);
default:
return input;
}
}
function updateStats(text) {
const chars = text.length;
const words = text.trim() ? text.trim().split(/\s+/).length : 0;
const lines = text.split('\n').length;
const size = formatBytes(chars);
charCount.textContent = chars.toLocaleString();
wordCount.textContent = words.toLocaleString();
lineCount.textContent = lines.toLocaleString();
sizeInfo.textContent = size;
}
function formatBytes(bytes) {
if (bytes === 0) return '0 B';
const k = 1024;
const sizes = ['B', 'KB', 'MB', 'GB'];
const i = Math.floor(Math.log(bytes) / Math.log(k));
return parseFloat((bytes / Math.pow(k, i)).toFixed(2)) + ' ' + sizes[i];
}
function getCharacterFrequency(str) {
const frequency = {};
const totalChars = str.length;
// Count each character
for (let char of str) {
frequency[char] = (frequency[char] || 0) + 1;
}
// Sort by character lexicographically (alphabetically)
const sortedChars = Object.entries(frequency)
.sort((a, b) => a[0].localeCompare(b[0]));
// Display as interactive table
displayFrequencyTable(sortedChars, totalChars);
// Return a simple text version for copy functionality
return sortedChars.map(([char, count]) => {
const displayChar = char === ' ' ? '[space]' :
char === '\n' ? '[newline]' :
char === '\t' ? '[tab]' :
char === '\r' ? '[carriage-return]' : char;
return `${displayChar}: ${count}`;
}).join('\n');
}
function displayFrequencyTable(sortedChars, totalChars) {
const tbody = document.getElementById('frequency-tbody');
const summary = document.getElementById('frequency-summary');
// Clear previous data
tbody.innerHTML = '';
// Populate table rows
sortedChars.forEach(([char, count]) => {
const percentage = ((count / totalChars) * 100).toFixed(1);
const displayChar = char === ' ' ? '⎵' :
char === '\n' ? '↵' :
char === '\t' ? '⇥' :
char === '\r' ? '⏎' : char;
const row = document.createElement('tr');
row.className = 'hover:bg-slate-600/30 transition-colors duration-200';
row.innerHTML = `
<td class="py-2 px-4 text-gray-200 font-mono">${displayChar}</td>
<td class="py-2 px-4 text-center text-blue-400 font-semibold">${count}</td>
<td class="py-2 px-4 text-center text-green-400">${percentage}%</td>
`;
tbody.appendChild(row);
});
// Update summary
summary.innerHTML = `
<div class="flex justify-between items-center">
<span>📊 Total unique characters: <span class="text-blue-400 font-semibold">${sortedChars.length}</span></span>
<span>📝 Total characters: <span class="text-green-400 font-semibold">${totalChars}</span></span>
</div>
`;
}
// Example text on page load
window.addEventListener('load', () => {
stringInput.value = 'Hello World! This is a sample text for transformation.';
});
});
</script>
</div>
</div>
<!-- Sidebar Scripts -->
<!-- Include Final Sidebar -->
<div id="sidebar-container"></div>
<script>
// Load final_sidebar.html content
fetch('final_sidebar.html')
.then(response => response.text())
.then(html => {
document.getElementById('sidebar-container').innerHTML = html;
})
.catch(error => {
console.error('Error loading sidebar:', error);
});
</script>
</body>
</html>