JavaScript Formatter

Lightweight JavaScript beautifier — newlines and 2-space brace indentation for minified code.

JavaScript Formatter

Lightweight JavaScript beautifier — newlines and 2-space brace indentation for minified code.

Paste minified or cramped JavaScript to get each statement on its own line with brace blocks indented two spaces. The formatter is string-, comment-, and template-literal-aware, keeps else/catch on the same line as the closing brace, and never splits the semicolons inside for(;;) headers. A quick cleanup tool — not a full prettier replacement.

Lightweight beautifier — adds newlines and brace indentation. Not a full prettier replacement.

How to use this calculator

  1. Paste minified or compact JavaScript into the input box.
  2. Click Beautify.
  3. Review the output — statements on their own lines, blocks indented two spaces.
  4. Diff against the original before using it anywhere important.
  5. Copy the readable version for debugging or review.

The formula

The source is scanned while tracking strings, comments, template literals, and parenthesis depth; semicolons outside for-headers and braces trigger newlines, with indentation following brace depth and else/catch/finally kept on the closing brace's line.

Worked example

Beautifying function greet(name){if(name){return "hi "+name;}return "hi";} produces a six-line function with the if block indented one level and the return statements at their correct depths — verified character-for-character in tests.

Frequently Asked Questions

How is this different from Prettier?

Prettier is a full opinionated code formatter that rewrites expressions, normalizes quotes, and enforces an entire style guide. This tool does one lightweight job: it puts statements on separate lines and indents brace blocks so minified code becomes skimmable. It never reorders, renames, or restructures your code.

Will it break my code?

It only inserts whitespace — newlines and indentation — which JavaScript ignores outside of strings. Strings, comments, and template literals (including ${} interpolation) are tracked so their contents are never altered. As with any formatter, diff the result before shipping.

What are the known limitations?

Regex literals containing // can be misread as line comments, since telling division apart from regex requires full parsing. Very long single expressions are not wrapped, and spacing inside expressions is left as written. For production codebases, use Prettier or ESLint.

Does it handle for loops correctly?

Yes — semicolons inside for(;;) headers are not treated as statement terminators, so for(let i=0;i<3;i++) stays on one line while the loop body is indented beneath it.

Is my code uploaded anywhere?

No. Beautification runs entirely in your browser, so proprietary or unreleased code never leaves the page.