mirror of
https://github.com/beautifier/js-beautify.git
synced 2024-11-23 20:59:43 +00:00
Flesh out README with Python and JavaScript sections, outlining CLI options and defaults.
This commit is contained in:
parent
f68fd06345
commit
09f3a36f0e
72
README.md
72
README.md
@ -8,7 +8,11 @@ JavaScript, unpack scripts packed by Dean Edward’s popular packer,
|
||||
as well as deobfuscate scripts processed by
|
||||
[javascriptobfuscator.com](http://javascriptobfuscator.com/).
|
||||
|
||||
To beautify from the command-line you can use provided python script/library.
|
||||
## Usage
|
||||
|
||||
To beautify from the command-line you can use the provided Python script/library or [npm](http://npmjs.org/) package.
|
||||
|
||||
### Python
|
||||
|
||||
`./js-beautify file.js` beautifies a file, output goes to `stdout`.
|
||||
|
||||
@ -28,9 +32,75 @@ opts.indent_size = 2
|
||||
res = jsbeautifier.beautify('some javascript', opts)
|
||||
```
|
||||
|
||||
### JavaScript
|
||||
|
||||
As an alternative to the Python script, you may install the NPM package `js-beautify`. When installed globally, it provides an executable `jsbeautify` script. As with the Python script, the beautified result is sent to `stdout` unless otherwise configured.
|
||||
|
||||
```js
|
||||
jsbeautify foo.js
|
||||
```
|
||||
|
||||
`jsbeautify -h`
|
||||
|
||||
You can also use `js-beautify` as a `node` library:
|
||||
|
||||
```js
|
||||
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
|
||||
|
||||
These are the command-line flags for both Python and JS scripts:
|
||||
|
||||
CLI Options:
|
||||
-f, --file Input file(s) (Pass '-' for stdin). These can also be passed directly.
|
||||
-i, --in-place Write output in-place (replacing input)
|
||||
-o, --outfile Write output to file (default stdout)
|
||||
|
||||
Beautifier Options:
|
||||
-s, --indent-size Indentation size [default: 4]
|
||||
-c, --indent-char Indentation character [default: " "]
|
||||
-l, --indent-level Initial indentation level [default: 0]
|
||||
-t, --indent-with-tabs Indent with tabs, overrides -s and -c
|
||||
-p, --preserve-newlines Do not preserve existing line-breaks [default: true]
|
||||
-m, --max-preserve-newlines Maximum number of line-breaks to be preserved in one chunk [default: 10]
|
||||
-j, --jslint-happy Enable jslint-stricter mode
|
||||
-b, --brace-style Brace style [collapse|expand|end-expand|expand-strict] [default: "collapse"]
|
||||
-k, --keep-array-indentation Preserve array indentation
|
||||
-a, --indent-case Indent case inside switch
|
||||
-x, --unescape-strings Decode printable characters encoded in xNN notation
|
||||
|
||||
These correspond to underscored option keys for both library interfaces:
|
||||
|
||||
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,
|
||||
indent_case: false,
|
||||
unescape_strings: false
|
||||
}
|
||||
|
||||
## License
|
||||
|
||||
You are free to use this in any way you want, in case you find this
|
||||
useful or working for you.
|
||||
|
||||
## Credits
|
||||
|
||||
Written by Einar Lielmanis, <einar@jsbeautifier.org>
|
||||
Python version flourished by Stefano Sanfilippo <a.little.coder@gmail.com>
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user