JavaScript Formatter
Format JavaScript, or minify and mangle it
What is JavaScript Formatter?
A JavaScript formatter re-prints your code using Prettier rules, with a choice of single or double quotes. Minify mode runs Terser for syntax-level compression and identifier mangling, and reports the size reduction. Everything runs locally in your browser, so your code is never uploaded.
How to use JavaScript Formatter
- 1Paste JavaScript or JSX code.
- 2In format mode, switch between single and double quote styles.
- 3Minify mode strips whitespace, collapses expressions, and mangles variable names in a single pass.
- 4Syntax errors are shown as the raw Terser or Prettier message so you can locate them.
How do I do this in code?
Use the tool above for one-off work; for anything you repeat, move it into a script or your project.
# Formatting: let Prettier own it, and enforce it in CI
npx prettier --write "src/**/*.{js,jsx,ts,tsx}"
npx prettier --check "src/**/*.{js,jsx,ts,tsx}"
# Minification: leave it to your build tool (esbuild / terser) instead of doing it by hand
npx terser input.js --compress --mangle -o output.min.jsFrequently asked questions
Can minified code be restored to its original form?+
Not completely. Minification discards variable names and comments, and formatting can only bring back the layout, never the lost semantic information. The right way to debug production issues is to generate source maps and keep them.
Why does minification report a syntax error?+
Usually the code contains syntax the current parser does not support, such as uncompiled TypeScript type annotations, decorators, or a very recent proposal. Compile it first, then minify.
Related tools
All toolsJSON Formatter
Format, minify, and validate JSON with line-and-column error reporting
JSON Validator
Validate JSON syntax and pinpoint the failing line and column
JSON Viewer
Explore JSON as a collapsible tree and read off access paths
JSON Escape / Unescape
Escape and unescape JSON strings
SQL Formatter
Beautify SQL per dialect, including MySQL and PostgreSQL
XML Formatter
Pretty-print or minify XML while checking that every tag is closed