Hello

    `, py: `# Calculate factorial def factorial(n): """Return n! — recursive docstring.""" if n <= 1: return 1 return n * factorial(n - 1) # recursive call`, c: `// QuickSort partition int partition(int arr[], int low, int high) { int pivot = arr[high]; /* last element */ int i = (low - 1); for (int j = low; j < high; j++) { if (arr[j] <= pivot) i++; } return i + 1; }`, sql: `-- Top customers query SELECT id, name, email /* primary contact */ FROM users WHERE active = 1; -- only active`, }; function stripJS(src, opts) { let out = ''; let i = 0; const n = src.length; let inStr = null; while (i < n) { const c = src[i]; const n1 = src[i + 1]; if (inStr) { out += c; if (c === '\\' && i + 1 < n) { out += src[i + 1]; i += 2; continue; } if (c === inStr) inStr = null; i++; continue; } if (c === '/' && n1 === '/') { while (i < n && src[i] !== '\n') i++; continue; } if (c === '/' && n1 === '*') { if (opts.keepDoc && src.slice(i, i + 3) === '/**') { const end = src.indexOf('*/', i + 3); if (end >= 0) { out += src.slice(i, end + 2); i = end + 2; continue; } } i += 2; while (i < n - 1 && !(src[i] === '*' && src[i + 1] === '/')) i++; if (i < n - 1) i += 2; if (opts.blank) out += '\n'; continue; } if (c === '"' || c === "'" || c === '`') { inStr = c; out += c; i++; continue; } out += c; i++; } return out; } function stripCSS(src, opts) { let out = ''; let i = 0; const n = src.length; while (i < n) { if (src[i] === '/' && src[i + 1] === '*') { i += 2; while (i < n - 1 && !(src[i] === '*' && src[i + 1] === '/')) i++; if (i < n - 1) i += 2; if (opts.blank) out += '\n'; continue; } if (src[i] === '"' || src[i] === "'") { const q = src[i]; out += src[i++]; while (i < n && src[i] !== q) { if (src[i] === '\\') out += src[i++]; out += src[i++]; } if (i < n) out += src[i++]; continue; } out += src[i++]; } return out; } function stripHTML(src, opts) { let out = ''; let i = 0; const n = src.length; while (i < n) { if (src.slice(i, i + 4) === '', i + 4); i = end >= 0 ? end + 3 : n; if (opts.blank) out += '\n'; continue; } out += src[i++]; } return out; } function stripHash(src, opts) { let out = ''; const lines = src.split('\n'); for (const line of lines) { const idx = line.indexOf('#'); if (idx >= 0) { out += line.slice(0, idx).trimEnd(); } else { out += line; } out += '\n'; } return out; } function stripC(src, opts) { // Same as JS but no template literals / regex return stripJS(src, opts); } function stripDash(src, opts) { let out = ''; const lines = src.split('\n'); for (const line of lines) { const trimmed = line.trimStart(); if (trimmed.startsWith('--')) { out += ''; } else { // also strip -- inside line (but not inside strings - quick check) const idx = line.indexOf(' --'); if (idx >= 0 && !line.slice(0, idx).includes("'") && !line.slice(0, idx).includes('"')) { out += line.slice(0, idx); } else { out += line; } } out += '\n'; } return out; } function strip() { const lang = $('#lang').value; const src = $('#input').value; if (!src) { $('#output').textContent = ''; $('#stats').innerHTML = ''; return; } const opts = { keepDoc: $('#keepDoc').checked, blank: $('#keepBlank').checked, trim: $('#trimLines').checked, }; let out; if (lang === 'js') out = stripJS(src, opts); else if (lang === 'css') out = stripCSS(src, opts); else if (lang === 'html') out = stripHTML(src, opts); else if (lang === 'py') out = stripHash(src, opts); else if (lang === 'c') out = stripC(src, opts); else if (lang === 'sql') out = stripDash(src, opts); else out = src; if (opts.trim) out = out.split('\n').map(l => l.replace(/\s+$/, '')).join('\n'); if (!opts.blank) out = out.replace(/\n{3,}/g, '\n\n'); $('#output').textContent = out; const before = src.length; const after = out.length; const saved = before - after; const pct = before ? Math.round(saved / before * 100) : 0; $('#stats').innerHTML = `Before: ${before.toLocaleString()} charsAfter: ${after.toLocaleString()} charsRemoved: ${saved.toLocaleString()} chars (${pct}%)`; } ['input','lang','keepDoc','keepBlank','trimLines'].forEach(id => { const el = $('#' + id); el.addEventListener('input', strip); el.addEventListener('change', strip); }); function loadExample() { $('#lang').value = 'js'; $('#input').value = EXAMPLES.js; strip(); } function doCopy() { GZ.copyText($('#output').textContent); } function doClear() { $('#input').value = ''; $('#output').textContent = ''; $('#stats').innerHTML = ''; } $('#toolbar').innerHTML = ` `; GZ.renderToolPage({ category:'dev', titleKey:'toolTitle', descKey:'toolDesc', howToSteps:['step1','step2','step3','step4'], related:[ {icon:'📜',href:'/dev/js-minifier.html',name:'JS Minifier'}, {icon:'📄',href:'/dev/html-minifier.html',name:'HTML Minifier'}, {icon:'🎨',href:'/css-tools/minify.html',name:'CSS Minifier'}, {icon:'🔧',href:'/dev/regex.html',name:'Regex Tester'}, ] }); loadExample();