JavaScript Formatter

Re-indent JavaScript with consistent braces and line breaks, using a tokenizer that keeps strings, template literals, comments, and regex intact.

A JavaScript formatter re-indents code by brace, bracket, and parenthesis depth. A tokenizer reads strings, template literals, comments, and regex literals first, so their contents survive unchanged.

Output

                

Paste or type something above.

Questions about javascript formatter

Will it rename anything?
No. Only whitespace and line breaks change. Identifiers, strings, and numbers are never touched.
How does it tell division from a regex?
It looks at the previous significant token. After an operator, an opening bracket, or a keyword, a slash starts a regex, otherwise it is division.
Does it fix broken code?
No. An unbalanced quote or comment is reported as an error rather than reformatted into something that does not compile.