explaingit

beautifier/js-beautify

8,964JavaScriptAudience · developerComplexity · 2/5Setup · easy

TLDR

A tool that reformats minified or messy JavaScript, CSS, and HTML into clean, readable, properly indented code, available as a command-line tool, a Node.js or Python library, and a browser widget.

Mindmap

mindmap
  root((repo))
    What it does
      Code beautifier
      Unminifies code
    Languages
      JavaScript
      CSS
      HTML
    Delivery Forms
      CLI tool
      Node.js library
      Python library
      Browser script
    Features
      Configurable indent
      Packer unpacking
      beautifier.io demo
Click or tap to explore — scroll the page freely

Code map

Detail Auto

An interactive map of this repo's files and how they connect — its source is parsed live in your browser. Click Visualize to build it.

filefunction / class

Things people build with this

USE CASE 1

Unminify a third-party JavaScript file to read its logic without a source map.

USE CASE 2

Add auto-formatting to a Node.js or Python build pipeline to enforce consistent code style.

USE CASE 3

Embed the browser library in a web app to let users paste and beautify code snippets client-side.

USE CASE 4

Unpack Dean Edwards packer-compressed JavaScript to inspect what a script actually does.

Tech stack

JavaScriptPythonNode.jsCSSHTML

Getting it running

Difficulty · easy Time to first run · 5min

Try it instantly at beautifier.io with no install. For local use: `npm install -g js-beautify` or `pip install jsbeautifier`.

No license information is mentioned in the explanation.

In plain English

JS Beautifier is a tool that takes messy or compressed JavaScript, CSS, or HTML code and reformats it so it is easier to read. When code has been minified (stripped of all spacing to make it smaller) or obfuscated (deliberately scrambled to hide its logic), this tool reverses some of that and produces a cleanly indented, human-readable version. You can try it in your browser at beautifier.io without installing anything. The project is available in three forms. There is a command-line tool that runs with Node.js or Python. There is a library you can add to a Node.js project or a Python project and call from your own code. There is also a web library version that you can include directly in an HTML page using a script tag, which exposes three functions for beautifying JavaScript, CSS, and HTML from within a browser. The Node.js version handles JavaScript, CSS, and HTML. The Python version handles JavaScript only by default, though a separate Python package called cssbeautifier handles CSS. Configuration options let you control things like how many spaces to use for indentation and how to handle brackets and empty parentheses. One notable use case is analyzing code that was packed using Dean Edwards' packer, an older JavaScript compression technique. The beautifier recognizes this format and can unpack it before reformatting. It also partially handles scripts processed by the javascript-obfuscator npm package, though the README does not claim complete deobfuscation for all cases. The README notes that the project is widely used but currently short on contributors. The existing maintainers have limited time, and the project has open bugs as well as known issues with its internal design. Contributions are being actively encouraged, with a set of issues labeled as good starting points for new contributors.

Copy-paste prompts

Prompt 1
Using the js-beautify Node.js library, write a script that reads a minified JavaScript file from disk, beautifies it with 2-space indentation, and writes the result to a new file.
Prompt 2
Show me how to use the js-beautify Python package from the command line to reformat a minified CSS file.
Prompt 3
Add js-beautify as a browser script tag and write the JavaScript to beautify a block of HTML pasted into a textarea when a button is clicked.
Prompt 4
How do I configure js-beautify to use tabs instead of spaces and place opening braces on the same line as function declarations?
Open on GitHub → Explain another repo

← beautifier on gitmyhub — every repo by this author, as a profile.

Verify against the repo before relying on details.