Overview
The default export ofjs-beautify is a function that beautifies JavaScript source code. All three aliases below are equivalent:
Function signature
Parameters
The JavaScript source code string to beautify. You can also pass minified code, bookmarklets, or scripts packed by Dean Edward’s packer.
Configuration options object. All keys use underscores (e.g.,
indent_size). Options loaded from .jsbeautifyrc or environment variables are merged with lower priority than options passed directly here.Return value
The beautified JavaScript source code as a string.
Examples
Configuration option names are the same as CLI flag names but with underscores instead of dashes. For example,
--indent-size 2 maps to { indent_size: 2 }.Configuration loading (Node.js only)
In the Node.js environment, options are resolved from the following sources in priority order (highest to lowest):- Options passed directly to the function
jsbeautify_-prefixed environment variables- A JSON config file specified via
--config - A
.jsbeautifyrcJSON file found at or above the current working directory
Language-specific overrides
When loading from.jsbeautifyrc, you can scope settings to a specific language using a nested key: