JavaScript Formatter
Format JavaScript with clean indentation and readable spacing. Paste code, format it instantly, then copy the result for review and PRs.
JavaScript Formatter
SIMILAR TOOLS
What this does
So you have got JavaScript that arrived minified, or that has drifted into a mess of uneven indentation, and reading it is slow going. This cleans it up. Paste the code, hit Format, and you get it back with tidy indentation and consistent spacing.
How to use it
- Paste your JavaScript into the box.
- Hit Format.
- Copy the formatted code with the Copy button.
How it works
The work is handled by js-beautify, a long standing JavaScript beautifier. It takes your code and reprints it with even indentation, four spaces deep, and sensible spacing around the parts that need it, turning a dense block into something readable. Everything runs in the browser, which matters when the code is not yours to share, since your script is not uploaded anywhere.
Where a beautifier stops
It helps to know where a beautifier stops. This reformats how your code looks, it does not change what it does, and it does not judge whether it is any good. It will not rename a confusing variable, flag an unused one, or warn you about a bug, that is the job of a linter such as ESLint.
What it gives you is readability. Take a minified bundle or a chaotically indented file, run it through, and you can actually follow the logic again. For reading someone else's code, or cleaning up your own before a review, that is usually exactly what you need.
Questions people ask
Does beautifying change how my code runs?
No. It only touches whitespace and layout. The behaviour of your JavaScript is left untouched.
Is this the same as a linter?
No. A linter checks for problems and enforces style rules. This simply reformats the code so it is easier to read.
Can it unminify a bundle?
It can re-indent and space out minified code so you can read it, yes. It cannot bring back the original variable names, since those are gone for good once code is minified.
Is my code uploaded?
No. It all runs in your browser, so the script you paste stays on your machine.
References
- Beautifier. js-beautify: Beautifier for JavaScript. https://github.com/beautifier/js-beautify
- MDN Web Docs. JavaScript. https://developer.mozilla.org/en-US/docs/Web/JavaScript
Sugam Baskota is a senior software engineer and Computer Science graduate from UT Arlington, with interests in user scripts, browser extensions, developer tooling, and productivity systems. He spends time building practical utilities and extensions in the kinds of workflows Eon is designed to simplify. At Eon Tools, he reviews useful, password, and developer tools.