🌐
GitHub
github.com › beautifier › js-beautify
JS Beautifier
Beautifier for javascript . Contribute to beautifier/js-beautify development by creating an account on GitHub.
Author   beautifier
🌐
GitHub
github.com › topics › js-beautify
js-beautify · GitHub Topics · GitHub
Sensible presets and some tweaks for beautifying HTML with js-beautify according to my preferences.
🌐
Beautifier
beautifier.io
Online JavaScript beautifier
Chrome, in case the built-in CSS and javascript formatting isn't enough for you: — Quick source viewer by Tomi Mickelsson (github, blog), — Javascript and CSS Code beautifier by c7sky, — jsbeautify-for-chrome by Tom Rix (github), — Pretty Beautiful JavaScript by Will McSweeney — Stackoverflow Code Beautify by Making Odd Edit Studios (github).
🌐
GitHub
github.com › beautifier › js-beautify-java
GitHub - beautifier/js-beautify-java: A Java port of js-beautify
A Java port of js-beautify. Contribute to beautifier/js-beautify-java development by creating an account on GitHub.
Starred by 13 users
Forked by 4 users
Languages   Java 64.4% | JavaScript 23.3% | HTML 10.3% | Mustache 2.0%
🌐
GitHub
github.com › PortSwigger › js-beautifier
GitHub - PortSwigger/js-beautifier: Burp Suite JS Beautifier
Burp Suite JS Beautifier. Contribute to PortSwigger/js-beautifier development by creating an account on GitHub.
Starred by 5 users
Forked by 2 users
Languages   Java 59.7% | JavaScript 40.1% | HTML 0.2%
🌐
GitHub
github.com › maksimr › vim-jsbeautify
GitHub - maksimr/vim-jsbeautify: vim plugin which formated javascript files by js-beautify
wget https://github.com/beautify-web/js-beautify/archive/v1.8.9.zip && unzip v1.8.9.zip && cp -rf js-beautify-1.8.9/ ~/.vim/plugin/lib/
Starred by 752 users
Forked by 68 users
Languages   Vim Script 65.0% | JavaScript 33.9%
🌐
GitHub
github.com › HookyQR › VSCodeBeautify
GitHub - HookyQR/VSCodeBeautify: Enable js-beautify (https://github.com/beautify-web/js-beautify) in VS Code · GitHub
Enable js-beautify (https://github.com/beautify-web/js-beautify) in VS Code - HookyQR/VSCodeBeautify
Author   HookyQR
🌐
GitHub
github.com › TALLStackHub › js-beautify
GitHub - TALLStackHub/js-beautify · GitHub
The whole idea behind this package to beautify the blade files such as html with all configrations & rules. This package also support beautify js & css with the same API of original js-beautify
Author   TALLStackHub
🌐
GitHub
github.com › sticeap › sublime-beautify
GitHub - sticeap/sublime-beautify: Beautifier for javascript
You can beautify javascript using JS Beautifier in your web browser, or on the command-line using node.js or python.
Author   sticeap
🌐
Package Control
packagecontrol.io › packages › Javascript Beautify
Javascript Beautify - Packages - Package Control
Project Deprecated , since that I am busy with another project and most of the time I use atom, the project deprecated , andbody who use js beautify can use https://github.com/jdc0589/JsFormat
Find elsewhere
🌐
GitHub
github.com › lvqingan › js-beautify-php
GitHub - lvqingan/js-beautify-php: javascript source code formatter written in PHP
javascript source code formatter written in PHP. Contribute to lvqingan/js-beautify-php development by creating an account on GitHub.
Starred by 6 users
Forked by 4 users
Languages   PHP
🌐
Homebrew
formulae.brew.sh › formula › js-beautify
js-beautify — Homebrew Formulae
Formula code: js-beautify.rb on GitHub · Bottle (binary package) installation support provided. Current versions: Depends on: Conflicts with: jsbeautifier ·
Top answer
1 of 10
76

First, pick your favorite Javascript based Pretty Print/Beautifier. I prefer the one at http://jsbeautifier.org/, because it's what I found first. Downloads its file https://github.com/beautify-web/js-beautify/blob/master/js/lib/beautify.js

Second, download and install The Mozilla group's Java based Javascript engine, Rhino. "Install" is a little bit misleading; Download the zip file, extract everything, place js.jar in your Java classpath (or Library/Java/Extensions on OS X). You can then run scripts with an invocation similar to this

java -cp js.jar org.mozilla.javascript.tools.shell.Main name-of-script.js

Use the Pretty Print/Beautifier from step 1 to write a small shell script that will read in your javascript file and run it through the Pretty Print/Beautifier from step one. For example

//original code    
(function() { ... js_beautify code ... }());

//new code
print(global.js_beautify(readFile(arguments[0])));

Rhino gives javascript a few extra useful functions that don't necessarily make sense in a browser context, but do in a console context. The function print does what you'd expect, and prints out a string. The function readFile accepts a file path string as an argument and returns the contents of that file.

You'd invoke the above something like

java -cp js.jar org.mozilla.javascript.tools.shell.Main beautify.js file-to-pp.js

You can mix and match Java and Javascript in your Rhino run scripts, so if you know a little Java it shouldn't be too hard to get this running with text-streams as well.

2 of 10
64

UPDATE April 2014:

The beautifier has been rewritten since I answered this in 2010. There is now a python module in there, an npm Package for nodejs, and the jar file is gone. Please read the project page on github.com.

Python style:

$ pip install jsbeautifier

NPM style:

$ npm -g install js-beautify

to use it (this will return the beatified js file on the terminal, the main file remains unchanged):

$ js-beautify file.js

To make the changes take effect on the file, you should use this command:

$ js-beautify -r file.js

Original answer

Adding to Answer of @Alan Storm

the command line beautifier based on http://jsbeautifier.org/ has gotten a bit easier to use, because it is now (alternatively) based on the V8 javascript engine (c++ code) instead of rhino (java-based JS engine, packaged as "js.jar"). So you can use V8 instead of rhino.

How to use:

download jsbeautifier.org zip file from http://github.com/einars/js-beautify/zipball/master

(this is a download URL linked to a zip file such as http://download.github.com/einars-js-beautify-10384df.zip)

old (no longer works, jar file is gone)

java -jar js.jar  name-of-script.js

new (alternative)

install/compile v8 lib FROM svn, see v8/README.txt in above-mentioned zip file

./jsbeautify somefile.js

-has slightly different command line options than the rhino version,

-and works great in Eclipse when configured as an "External Tool"

🌐
GitHub
github.com › jlbfalcao › js-beautify-v8.tmbundle
jlbfalcao/js-beautify-v8.tmbundle
A faster Javascript Beautifier textmate bundle. Contribute to jlbfalcao/js-beautify-v8.tmbundle development by creating an account on GitHub.
Author   jlbfalcao
🌐
GitHub
github.com › beautify-web › js-beautify › blob › master › CHANGELOG.md
js-beautify/CHANGELOG.md at main
Beautifier for javascript . Contribute to beautifier/js-beautify development by creating an account on GitHub.
Author   beautifier
🌐
GitHub
github.com › denis-ivanov › Jsbeautifier
GitHub - denis-ivanov/Jsbeautifier: Beautifier for javascript
Beautifier for javascript · This library is port of https://github.com/einars/js-beautify on C#
Starred by 67 users
Forked by 34 users
Languages   C#
🌐
GitHub
github.com › yasuyk › web-beautify
GitHub - yasuyk/web-beautify: Format HTML, CSS and JavaScript/JSON by js-beautify
web-beautify is a formatting package of HTML, CSS and JavaScript/JSON for Emacs.
Starred by 223 users
Forked by 21 users
Languages   Emacs Lisp 82.2% | Makefile 17.8%
🌐
GitHub
github.com › beautifier › js-beautify › blob › main › python › jsbeautifier › __init__.py
js-beautify/python/jsbeautifier/__init__.py at main · beautifier/js-beautify
Beautifier for javascript . Contribute to beautifier/js-beautify development by creating an account on GitHub.
Author   beautifier
🌐
GitHub
github.com › beautify-web › js-beautify › blob › master › index.html
js-beautify/index.html at main
Beautifier for javascript . Contribute to beautifier/js-beautify development by creating an account on GitHub.
Author   beautifier