Installation
The Python
jsbeautifier package only reformats JavaScript. It does not support HTML or CSS. For CSS, install the separate cssbeautifier package.Module
Functions
beautify()
Beautify a JavaScript source string.
The JavaScript source code string to beautify.
An options object returned by
default_options(). If omitted, default options are used.The beautified JavaScript source code.
beautify_file()
Read a JavaScript file and return beautified output as a string.
Path to the JavaScript file. Pass
"-" to read from stdin.An options object returned by
default_options().The beautified JavaScript source code.
default_options()
Return a BeautifierOptions instance populated with default values.
A
BeautifierOptions object. Mutate its attributes before passing to beautify() or beautify_file().BeautifierOptions attributes
All attributes mirror the CLI flag names with underscores instead of dashes.
Examples
CLI (Python)
Thejsbeautifier package also installs a js-beautify command:
js-beautify --help for a full list of CLI flags.