On GitHub, juliangarnier/js-beautify has picked up 11 stars, JavaScript. Beautifier for javascript
Snapshot summary built from the project's own GitHub metadata — there's no written TopGit review yet. The page will update automatically when a full review is published.
WHY NO REVIEW YET
TopGit writes full reviews for the most-starred, most-requested repositories. This page is a snapshot until then — see the READ ME tab for the original README in full.
This little beautifier will reformat and reindent bookmarklets, ugly
JavaScript, unpack scripts packed by Dean Edward’s popular packer,
as well as deobfuscate scripts processed by
javascriptobfuscator.com.
Usage
You can beautify javascript using JS Beautifier in your web browser, or on the command-line using node.js or python.
Web Browser
Open jsbeautifier.org. Options are available via the UI.
Python
To beautify using python:
$ pip install jsbeautifier
$ js-beautify file.js
Beautified output goes to stdout.
To use jsbeautifier as a library is simple:
import jsbeautifier
res = jsbeautifier.beautify('your javascript string')
res = jsbeautifier.beautify_file('some_file.js')
As an alternative to the Python script, you may install the NPM package js-beautify. When installed globally, it provides an executable js-beautify script. As with the Python script, the beautified result is sent to stdout unless otherwise configured.
$ npm -g install js-beautify
$ js-beautify foo.js
You can also use js-beautify as a node library (install locally, the npm default):
$ npm install js-beautify
var beautify = require('js-beautify').js_beautify,
fs = require('fs');
fs.readFile('foo.js', 'utf8', function (err, data) {
if (err) {
throw err;
}
console.log(beautify(data, { indent_size: 2 }));
});
Options
These are the command-line flags for both Python and JS scripts:
CLI Options:
-f, --file Input file(s) (Pass '-' for stdin)
-r, --replace Write output in-place, replacing input
-o, --outfile Write output to file (default stdout)
--config Path to config file
--type [js|css|html] ["js"]
-q, --quiet Suppress logging to stdout
-h, --help Show this help
-v, --version Show the version
Beautifier Options:
-s, --indent-size Indentation size [4]
-c, --indent-char Indentation character [" "]
-l, --indent-level Initial indentation level [0]
-t, --indent-with-tabs Indent with tabs, overrides -s and -c
-p, --preserve-newlines Preserve line-breaks (--no-preserve-newlines disables)
-m, --max-preserve-newlines Number of line-breaks to be preserved in one chunk [10]
-P, --space-in-paren Add padding spaces within paren, ie. f( a, b )
-j, --jslint-happy Enable jslint-stricter mode
-b, --brace-style [collapse|expand|end-expand] ["collapse"]
-B, --break-chained-methods Break chained method calls across subsequent lines
-k, --keep-array-indentation Preserve array indentation
-x, --unescape-strings Decode printable characters encoded in xNN notation
-w, --wrap-line-length Wrap lines at next opportunity after N characters [0]
-X, --e4x Pass E4X xml literals through untouched
--good-stuff Warm the cockles of Crockford's heart
These largely correspond to the underscored option keys for both library interfaces, which have these defaults:
In addition to CLI arguments, you may pass config to the JS executable via:
any jsbeautify_-prefixed environment variables
a JSON-formatted file indicated by the --config parameter
a .jsbeautifyrc file containing JSON data at any level of the filesystem above $PWD
Configuration sources provided earlier in this stack will override later ones.
You might notice that the CLI options and defaults hash aren't 100% correlated. Historically, the Python and JS APIs have not been 100% identical. For example, space_before_conditional is currently JS-only, and not addressable from the CLI script. There are a few other additional cases keeping us from 100% API-compatibility. Patches welcome!
CSS & HTML
In addition to the js-beautify executable, css-beautify and html-beautify are also provided as an easy interface into those scripts. Alternatively, js-beautify --css or js-beautify --html will accomplish the same thing, respectively.
// Programmatic access
var beautify_js = require('js-beautify'); // also available under "js" export
var beautify_css = require('js-beautify').css;
var beautify_html = require('js-beautify').html;
// All methods accept two arguments, the string to be beautified, and an options object.
The CSS & HTML beautifiers are much simpler in scope, and possess far fewer options.
CSS Beautifier Options:
-s, --indent-size Indentation size [4]
-c, --indent-char Indentation character [" "]
HTML Beautifier Options:
-s, --indent-size Indentation size [4]
-c, --indent-char Indentation character [" "]
-b, --brace-style [collapse|expand|end-expand] ["collapse"]
-S, --indent-scripts [keep|separate|normal] ["normal"]
-w, --wrap-line-length Maximum characters per line (0 disables) [250]
-p, --preserve-newlines Preserve existing line-breaks (--no-preserve-newlines disables)
-m, --max-preserve-newlines Maximum number of line-breaks to be preserved in one chunk [10]
-U, --unformatted List of tags (defaults to inline) that should not be reformatted
License
You are free to use this in any way you want, in case you find this
useful or working for you but you must keep the copyright notice and license. (MIT)
Thanks also to Jason Diamond, Patrick Hof, Nochum Sossonko, Andreas Schneider, Dave
Vasilevsky, Vital Batmanov, Ron Baldwin, Gabriel Harrison, Chris J. Shull,
Mathias Bynens, Vittorio Gambaletta and others.
[email protected]
TopGit's last sync did not record any GitHub topics for juliangarnier/js-beautify. GitHub topics appear in the right sidebar of a repository page; that's the authoritative place to check.
How active is development on juliangarnier/js-beautify?
The most recent commit recorded on juliangarnier/js-beautify was 13.3 years ago, based on the GitHub push timestamp. The repository has 1 forks — one of the better signals of community interest.
How many stars does juliangarnier/js-beautify have?
juliangarnier/js-beautify has 11 GitHub stars — refresh the page for the live number, or check github.com/juliangarnier/js-beautify. TopGit mirrors GitHub's count but does not claim minute-by-minute accuracy.
Is juliangarnier/js-beautify open source?
Yes — juliangarnier/js-beautify ships under the MIT license, which makes its source code freely readable (and, depending on license terms, forkable and reusable). Source: github.com/juliangarnier/js-beautify.
Where can I see juliangarnier/js-beautify in action?
The project maintains a homepage at http://jsbeautifier.org/. The README tab on this page also usually contains screenshots and a quickstart.
Where do I read more about juliangarnier/js-beautify?
This TopGit page is a snapshot — the READ ME tab shows the project's own README content (links stripped, images preserved). The GitHub repository at github.com/juliangarnier/js-beautify is the definitive source.
Read full README in the tab above.
Want a second opinion on js-beautify?
Ask an AI that can read this page — one click and you get its take on js-beautify.