Skip to content

Commit

Permalink
Update README.md
Browse files Browse the repository at this point in the history
  • Loading branch information
bitwiseman authored Jan 17, 2018
1 parent 23f3a17 commit d092453
Showing 1 changed file with 10 additions and 2 deletions.
12 changes: 10 additions & 2 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -65,8 +65,11 @@ res = jsbeautifier.beautify_file('some_file.js')
``` python
opts = jsbeautifier.default_options()
opts.indent_size = 2
opts.space_in_empty_paren = True
res = jsbeautifier.beautify('some javascript', opts)
```
The configuration option names are the same as the CLI names but with underscores instead of dashes. The example above would be set on the command-line as `--indent-size 2 --space-in-empty-paren`.


## JavaScript

Expand All @@ -83,18 +86,23 @@ You can also use `js-beautify` as a `node` library (install locally, the `npm` d
$ npm install js-beautify
```

Import and call the approriate beautifier method for javascript (js), css, or html. All three method signatures are `beautify(code, options)`. `code` is a the string of code to be beautified. options is an object with the settings you would like used to beautify the code.

The configuration option names are the same as the CLI names but with underscores instead of dashes. For example, `--indent-size 2 --space-in-empty-paren` would be `{ indent_size: 2, space_in_empty_paren: true }`.

```js
var beautify = require('js-beautify').js_beautify,
var beautify = require('js-beautify').js,
fs = require('fs');

fs.readFile('foo.js', 'utf8', function (err, data) {
if (err) {
throw err;
}
console.log(beautify(data, { indent_size: 2 }));
console.log(beautify(data, { indent_size: 2, space_in_empty_paren: true }));
});
```


## Options

These are the command-line flags for both Python and JS scripts:
Expand Down

0 comments on commit d092453

Please sign in to comment.