JavaScript 美容师 &缩小器

使用自定义缩进和大括号样式格式化杂乱的 JavaScript,或缩小文件大小。支持 ES6+。完全在您的浏览器中运行 - 您的代码永远不会离开您的设备。

美化·缩小·ES6+·客户端
Input 0 chars · 0 lines
Output 0 chars · 0 lines

如何美容与美化缩小 JavaScript

如何使用这个工具

将 JavaScript 粘贴到输入面板中,选择 美化 或者 缩小 从模式选项卡中,结果立即出现。在处理之前调整缩进大小、大括号样式和换行符处理等选项。点击 复制输出 复制到剪贴板或 下载.js 保存文件。

美化选项解释

  • 支架样式Collapse 保持 { 在同一条线上(K&R / 标准 JS)。 Expand 看跌期权 { 独行(奥尔曼风格)。 End-expand 是一个混合体,其中 elsecatch 获得新鲜的线条。
  • 保留换行符 — 将空白行保留在原来的位置。对于使用间距作为逻辑分组的代码很有用。
  • JSLint-快乐 — 与 Douglas Crockford 的 JSLint 强制执行的样式相匹配。函数表达式前面有一个空格 (,以及其他调整。
  • 取消转义字符串 — 皈依 \xNN\uNNNN 在安全的情况下转义回其字面字符。

缩小选项解释

  • 保持 /*!执照 */ - 保留以以下内容开头的注释 /*!,大多数库使用的约定来标记必须保留在分布式代码中的 MIT/Apache 版权标头。
  • 去掉最后一个分号 — 删除最后的 ;}。节省一个字节,但会使差异变得更加嘈杂,因此默认情况下处于关闭状态。

缩小器是故意保守的——它只删除空格和注释。确实如此 不是 重命名变量、修改属性或执行 AST 级别的死代码消除。用于积极优化使用 terser 或者 esbuild 在您的构建管道中。

由 js-beautify 提供支持

美化器的动力来自 js-beautify,VS Code、Sublime Text、Atom 和最流行的在线格式化程序使用相同的库。一切都在您的浏览器本地运行 - 没有上传步骤,没有服务器往返,也没有速率限制。粘贴 500 KB 的缩小包,并在几毫秒内完成格式化。

常问问题

我的 JavaScript 代码是否发送到服务器?

No. All beautification and minification happens entirely in your browser using js-beautify loaded from a CDN. Your code never leaves your device.

美化和缩小有什么区别?

Beautifying formats code with proper indentation and line breaks for human readability. Minifying removes whitespace, comments, and unnecessary characters to reduce file size for production deployment.

缩小器会重命名变量吗?

No. This tool performs whitespace and comment removal only. It does not rename variables, mangle identifiers, or perform AST-level optimizations. For that level of compression use Terser, UglifyJS, or esbuild in a build pipeline.

它可以处理 ES6+ 语法吗?

Yes. The beautifier supports modern JavaScript including arrow functions, template literals, async/await, classes, destructuring, spread/rest, optional chaining, and nullish coalescing.

有哪些支架样式可供选择?

Three styles: Collapse (opening brace on same line as the statement), Expand (opening brace on a new line), and End-Expand (opening on same line, but else and catch get new lines).

相关工具