LinuxCommandLibrary
GitHubF-DroidGoogle Play Store

js-beautify

formats JavaScript, HTML, and CSS files with consistent indentation and style

TLDR

Beautify JavaScript file
$ js-beautify [file.js]
copy
Beautify and save in place
$ js-beautify -r [file.js]
copy
Beautify HTML
$ html-beautify [file.html]
copy
Beautify CSS
$ css-beautify [file.css]
copy
Set indentation
$ js-beautify -s [4] [file.js]
copy
Use tabs
$ js-beautify -t [file.js]
copy
Output to file
$ js-beautify [input.js] -o [output.js]
copy

SYNOPSIS

js-beautify [options] [file...]

DESCRIPTION

js-beautify formats JavaScript, HTML, and CSS files with consistent indentation and style. It's useful for cleaning up minified code or enforcing consistent formatting.The tool provides separate commands for each language (js-beautify, html-beautify, css-beautify) or auto-detects based on extension.

PARAMETERS

-r, --replace

Replace file in place.
-o file
Output to file.
-s size
Indent size (default 4).
-t, --indent-with-tabs
Use tabs.
-e, --eol chars
End of line character.
-n, --end-with-newline
End with newline.
--type type
Force type: js, html, css.
-f file
Input file.
--config file
Configuration file.

CONFIGURATION

$ // .jsbeautifyrc
{
  "indent_size": 2,
  "indent_with_tabs": false,
  "end_with_newline": true,
  "brace_style": "collapse"
}
copy

INSTALL

brew install js-beautify
copy
nix profile install nixpkgs#js-beautify
copy

CAVEATS

May alter code semantics in edge cases. Large files may be slow. Doesn't validate code. Configuration precedence can be complex.

HISTORY

js-beautify was created by Einar Lielmanis as an online tool, later expanded to a command-line tool and library. It's widely used for code formatting and reversing minification.

SEE ALSO

prettier(1), eslint(1)

Braincup
Open source brain training for math, memory and focus
Braincup mini-games
41 mini-games · Apache-2.0
No ads · No tracking
Play in browser
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid
276 stars
From the maker of Linux Command Library
Copied to clipboard
Braincup
Open source brain training for math, memory and focus. 41 mini-games, from mental arithmetic to Sudoku, N-Back and Solo Chess.
Apache-2.0 licensed · No ads · No tracking · No account
From the maker of Linux Command Library
Download Braincup on the App StoreGet Braincup on Google PlayGet Braincup on F-Droid