PHPackages                             bchecketts/js-beautify - PHPackages - PHPackages  [Skip to content](#main-content)[PHPackages](/)[Directory](/)[Categories](/categories)[Trending](/trending)[Leaderboard](/leaderboard)[Changelog](/changelog)[Analyze](/analyze)[Collections](/collections)[Log in](/login)[Sign up](/register)

1. [Directory](/)
2. /
3. [Utility &amp; Helpers](/categories/utility)
4. /
5. bchecketts/js-beautify

ActiveLibrary[Utility &amp; Helpers](/categories/utility)

bchecketts/js-beautify
======================

fork of einars/js-beautify for use with composer

028.8kJavaScript

Since Dec 2Pushed 12y agoCompare

[ Source](https://github.com/bchecketts/js-beautify)[ Packagist](https://packagist.org/packages/bchecketts/js-beautify)[ RSS](/packages/bchecketts-js-beautify/feed)WikiDiscussions master Synced 3d ago

READMEChangelogDependenciesVersions (1)Used By (0)

JS Beautifier
=============

[](#js-beautifier)

[![Build Status](https://camo.githubusercontent.com/d93c629d3e11af934a6cb7a4a1a4464ccaae05cc75f327deea609cfeeb9e91dc/68747470733a2f2f7365637572652e7472617669732d63692e6f72672f65696e6172732f6a732d62656175746966792e706e673f6272616e63683d6d6173746572)](http://travis-ci.org/einars/js-beautify)[![NPM version](https://camo.githubusercontent.com/43aec3d503b633934db7d67eb8a0dcc1a86e8da91f876596114ccb20adb63308/68747470733a2f2f62616467652e667572792e696f2f6a732f6a732d62656175746966792e706e67)](http://badge.fury.io/js/js-beautify)

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](http://javascriptobfuscator.com/).

Usage
=====

[](#usage)

You can beautify javascript using JS Beautifier in your web browser, or on the command-line using node.js or python.

Web Browser
-----------

[](#web-browser)

Open [jsbeautifier.org](http://jsbeautifier.org/). Options are available via the UI.

Python
------

[](#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')
```

...or, to specify some options:

```
opts = jsbeautifier.default_options()
opts.indent_size = 2
res = jsbeautifier.beautify('some javascript', opts)
```

JavaScript
----------

[](#javascript)

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
-------

[](#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:

```
{
    "indent_size": 4,
    "indent_char": " ",
    "indent_level": 0,
    "indent_with_tabs": false,
    "preserve_newlines": true,
    "max_preserve_newlines": 10,
    "jslint_happy": false,
    "brace_style": "collapse",
    "keep_array_indentation": false,
    "keep_function_indentation": false,
    "space_before_conditional": true,
    "break_chained_methods": false,
    "eval_code": false,
    "unescape_strings": false,
    "wrap_line_length": 0
}
```

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 &amp; HTML

[](#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 &amp; 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:
  -I, --indent-inner-html       Indent  and  sections. Default is false.
  -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
=======

[](#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)

Credits
=======

[](#credits)

- Written by Einar Lielmanis,
- Python version flourished by Stefano Sanfilippo
- General maintenance and expansion by Liam Newman
- Command-line for node.js by Daniel Stockman

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. js-beautify@1.3.4

###  Health Score

26

—

LowBetter than 43% of packages

Maintenance20

Infrequent updates — may be unmaintained

Popularity20

Limited adoption so far

Community19

Small or concentrated contributor base

Maturity41

Maturing project, gaining track record

 Bus Factor2

2 contributors hold 50%+ of commits

How is this calculated?**Maintenance (25%)** — Last commit recency, latest release date, and issue-to-star ratio. Uses a 2-year decay window.

**Popularity (30%)** — Total and monthly downloads, GitHub stars, and forks. Logarithmic scaling prevents top-heavy scores.

**Community (15%)** — Contributors, dependents, forks, watchers, and maintainers. Measures real ecosystem engagement.

**Maturity (30%)** — Project age, version count, PHP version support, and release stability.

### Community

Maintainers

![](https://www.gravatar.com/avatar/a02d3ef2e837e7d67f622737157d3e63e7b981e1183dfd327a63751f674a6272?d=identicon)[bchecketts](/maintainers/bchecketts)

---

Top Contributors

[![bitwiseman](https://avatars.githubusercontent.com/u/1958953?v=4)](https://github.com/bitwiseman "bitwiseman (181 commits)")[![esseks](https://avatars.githubusercontent.com/u/464720?v=4)](https://github.com/esseks "esseks (92 commits)")[![einars](https://avatars.githubusercontent.com/u/38091?v=4)](https://github.com/einars "einars (42 commits)")[![VittGam](https://avatars.githubusercontent.com/u/615188?v=4)](https://github.com/VittGam "VittGam (19 commits)")[![rasmuserik](https://avatars.githubusercontent.com/u/496937?v=4)](https://github.com/rasmuserik "rasmuserik (10 commits)")[![mokkabonna](https://avatars.githubusercontent.com/u/230877?v=4)](https://github.com/mokkabonna "mokkabonna (9 commits)")[![nightwing](https://avatars.githubusercontent.com/u/341801?v=4)](https://github.com/nightwing "nightwing (6 commits)")[![ariya](https://avatars.githubusercontent.com/u/7288?v=4)](https://github.com/ariya "ariya (5 commits)")[![rcopera](https://avatars.githubusercontent.com/u/25367121?v=4)](https://github.com/rcopera "rcopera (4 commits)")[![evocateur](https://avatars.githubusercontent.com/u/5605?v=4)](https://github.com/evocateur "evocateur (4 commits)")[![quisquous](https://avatars.githubusercontent.com/u/462317?v=4)](https://github.com/quisquous "quisquous (3 commits)")[![alkavan](https://avatars.githubusercontent.com/u/188295?v=4)](https://github.com/alkavan "alkavan (3 commits)")[![sorich87](https://avatars.githubusercontent.com/u/230367?v=4)](https://github.com/sorich87 "sorich87 (3 commits)")[![zhizhangchen](https://avatars.githubusercontent.com/u/1154926?v=4)](https://github.com/zhizhangchen "zhizhangchen (2 commits)")[![bchecketts](https://avatars.githubusercontent.com/u/3952446?v=4)](https://github.com/bchecketts "bchecketts (2 commits)")[![dertseha](https://avatars.githubusercontent.com/u/1508944?v=4)](https://github.com/dertseha "dertseha (2 commits)")[![fmgdias](https://avatars.githubusercontent.com/u/1345417?v=4)](https://github.com/fmgdias "fmgdias (2 commits)")[![Infocatcher](https://avatars.githubusercontent.com/u/601488?v=4)](https://github.com/Infocatcher "Infocatcher (2 commits)")[![JessThrysoee](https://avatars.githubusercontent.com/u/238102?v=4)](https://github.com/JessThrysoee "JessThrysoee (2 commits)")[![jonschlinkert](https://avatars.githubusercontent.com/u/383994?v=4)](https://github.com/jonschlinkert "jonschlinkert (2 commits)")

### Embed Badge

![Health badge](/badges/bchecketts-js-beautify/health.svg)

```
[![Health](https://phpackages.com/badges/bchecketts-js-beautify/health.svg)](https://phpackages.com/packages/bchecketts-js-beautify)
```

###  Alternatives

[mascame/arrayer

Array manipulation with dot notation. Also prepares an array to be put in a file. Very useful for config files.

141.4k2](/packages/mascame-arrayer)

PHPackages © 2026

[Directory](/)[Categories](/categories)[Trending](/trending)[Changelog](/changelog)[Analyze](/analyze)
