JavaScript Formatter - DigiKitApp
Format compact JavaScript into readable code.
When should you use this?
Use this to make minified or poorly indented JavaScript code readable, for instance when inspecting a website's code.
When shouldn't you use this?
Instead of manually formatting your own code every time, installing an auto-formatting extension (Prettier) in your editor is more efficient long term.
Step-by-step
- Copy the code you want to read. The Sources tab in your browser's developer tools or a .min.js file are the usual places.
- Paste it into the "JavaScript code" field.
- Click "Run". The code comes back split into lines and indented.
- Copy the result into your editor so you get syntax highlighting, and use its search to jump to the functions or variables you care about.
Example
A third-party chat widget on your site keeps popping open on one particular page. Its script is a single line thousands of characters long. Run it through the formatter and functions and conditions break onto their own lines, with nested blocks clearly indented. Now you can find the condition that checks the page URL or a cookie and see why the widget fires there. That gives you either a precise bug report for the vendor or a setting to fix on your side.
What does the formatter do?
The tool rewrites JavaScript with each statement on its own line, indented two spaces per nesting level. A new line starts after {, and the indent grows; a new line starts after ;, and } steps the indent back one level. Example: function f(a){if(a){g();}else{h();}} becomes an indented structure of seven lines, with “} else {” kept on one line. Quoted strings, template strings and comments are left intact; semicolons inside parentheses (a for loop) and braces inside parentheses (callback functions) stay on the same line.
When using it
- The tool is a character-based tidier, not a parser. If a regular expression literal contains a quote or a brace, the output can break.
- Object literals are split into lines like blocks: const o={a:1,b:2}; spreads over a few lines.
- In code written without semicolons, statements stay on one line; the tool does not add semicolons.
- For complex or production code a formatter such as Prettier is safer.
Things to keep in mind
- Formatting only changes layout. Short names like a, b and c from minification stay as they are, so the code is readable but still takes some decoding.
- Deliberately obfuscated code can stay hard to follow even after formatting.
- If it's your own project and a source map exists, your browser's developer tools can show the original source directly. That beats formatting the minified output.
- Reading someone else's code is a good way to learn, but check the license before copying any of it into your own project.
Related ready-made prompts: Coding Prompts.
Frequently asked questions
Is the code/data I enter stored anywhere?
No, nothing is sent to a server or stored; processing happens entirely in your browser.
Does it work with large inputs?
Yes, though performance may degrade with very large inputs (several MB or more).
Is this tool free?
Yes, it's completely free for core use and requires no account.