# JS Beautifier
![CI](https://github.com/beautify-web/js-beautify/workflows/CI/badge.svg)
[![PyPI version](https://img.shields.io/pypi/v/jsbeautifier.svg)](https://pypi.python.org/pypi/jsbeautifier)
[![CDNJS version](https://img.shields.io/cdnjs/v/js-beautify.svg)](https://cdnjs.com/libraries/js-beautify)
[![NPM @latest](https://img.shields.io/npm/v/js-beautify.svg)](https://www.npmjs.com/package/js-beautify)
[![NPM @next](https://img.shields.io/npm/v/js-beautify/next.svg)](https://www.npmjs.com/package/js-beautify?activeTab=versions)
[![Join the chat at https://gitter.im/beautify-web/js-beautify](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/beautify-web/js-beautify?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[![Twitter Follow](https://img.shields.io/twitter/follow/js_beautifier.svg?style=social&label=Follow)](https://twitter.com/intent/user?screen_name=js_beautifier)
[![NPM stats](https://nodei.co/npm/js-beautify.svg?downloadRank=true&downloads=true)](https://www.npmjs.org/package/js-beautify) [![Greenkeeper badge](https://badges.greenkeeper.io/beautify-web/js-beautify.svg)](https://greenkeeper.io/)
This little beautifier will reformat and re-indent bookmarklets, ugly
JavaScript, unpack scripts packed by Dean Edward’s popular packer,
as well as partly deobfuscate scripts processed by the npm package
[javascript-obfuscator](https://github.com/javascript-obfuscator/javascript-obfuscator).
Open [beautifier.io](https://beautifier.io/) to try it out. Options are available via the UI.
# Contributors Needed
I'm putting this front and center above because existing owners have very limited time to work on this project currently.
This is a popular project and widely used but it desperately needs contributors who have time to commit to fixing both
customer facing bugs and underlying problems with the internal design and implementation.
If you are interested, please take a look at the [CONTRIBUTING.md](https://github.com/beautify-web/js-beautify/blob/main/CONTRIBUTING.md) then fix an issue marked with the ["Good first issue"](https://github.com/beautify-web/js-beautify/issues?q=is%3Aissue+is%3Aopen+label%3A%22good+first+issue%22) label and submit a PR. Repeat as often as possible. Thanks!
# Installation
You can install the beautifier for node.js or python.
## Node.js JavaScript
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.
```bash
$ npm -g install js-beautify
$ js-beautify foo.js
```
You can also use `js-beautify` as a `node` library (install locally, the `npm` default):
```bash
$ npm install js-beautify
```
## Node.js JavaScript (vNext)
The above install the latest stable release. To install beta or RC versions:
```bash
$ npm install js-beautify@next
```
## Web Library
The beautifier can be added on your page as web library.
JS Beautifier is hosted on two CDN services: [cdnjs](https://cdnjs.com/libraries/js-beautify) and rawgit.
To pull the latest version from one of these services include one set of the script tags below in your document:
```html
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.13.5/beautify.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.13.5/beautify-css.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.13.5/beautify-html.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.13.5/beautify.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.13.5/beautify-css.min.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/js-beautify/1.13.5/beautify-html.min.js"></script>
<script src="https://cdn.rawgit.com/beautify-web/js-beautify/v1.13.5/js/lib/beautify.js"></script>
<script src="https://cdn.rawgit.com/beautify-web/js-beautify/v1.13.5/js/lib/beautify-css.js"></script>
<script src="https://cdn.rawgit.com/beautify-web/js-beautify/v1.13.5/js/lib/beautify-html.js"></script>
```
Older versions are available by changing the version number.
Disclaimer: These are free services, so there are [no uptime or support guarantees](https://github.com/rgrove/rawgit/wiki/Frequently-Asked-Questions#i-need-guaranteed-100-uptime-should-i-use-cdnrawgitcom).
## Python
To install the Python version of the beautifier:
```bash
$ pip install jsbeautifier
```
Unlike the JavaScript version, the Python version can only reformat JavaScript. It does not work against HTML or CSS files, but you can install _css-beautify_ for CSS:
```bash
$ pip install cssbeautifier
```
# Usage
You can beautify javascript using JS Beautifier in your web browser, or on the command-line using node.js or python.
## Web Browser
Open [beautifier.io](https://beautifier.io/). Options are available via the UI.
## Web Library
The script tags above expose three functions: `js_beautify`, `css_beautify`, and `html_beautify`.
## Node.js JavaScript
When installed globally, the beautifier provides an executable `js-beautify` script. The beautified result is sent to `stdout` unless otherwise configured.
```bash
$ js-beautify foo.js
```
To use `js-beautify` as a `node` library (after install locally), import and call the appropriate beautifier method for javascript (js), css, or html. All three method signatures are `beautify(code, options)`. `code` is 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,
fs = require('fs');
fs.readFile('foo.js', 'utf8', function (err, data) {
if (err) {
throw err;
}
console.log(beautify(data, { indent_size: 2, space_in_empty_paren: true }));
});
```
## Python
After installing, to beautify using Python:
```bash
$ js-beautify file.js
```
Beautified output goes to `stdout` by default.
To use `jsbeautifier` as a library is simple:
```python
import jsbeautifier
res = jsbeautifier.beautify('your javascript string')
res = jsbeautifier.beautify_file('some_file.js')
```
...or, to specify some options:
```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`.
# Options
These are the command-line flags for both Python and JS scripts:
```text
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"] Select beautifier type (NOTE: Does *not* filter files, only defines which beautifier type to run)
-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 [" "]
-t, --indent-with-tabs Indent with tabs, overrides -s and -c
-e, --eol Character(s) to use as line terminators.
[first newline in file, otherwise "\n]
-n, --end-with-newline End output with newline
--editorconfig Use EditorConfig to set up the options
-l, --indent-level Initial indentation level [0]
-p, --preserve-newlines Preserve line-breaks (--no-preserv
没有合适的资源?快使用搜索试试~ 我知道了~
hbuilderx.zip
共2004个文件
png:797个
js:703个
json:270个
需积分: 0 0 下载量 199 浏览量
2023-11-02
15:19:35
上传
评论
收藏 32.43MB ZIP 举报
温馨提示
hbuilderx.zip
资源推荐
资源详情
资源评论
收起资源包目录
hbuilderx.zip (2004个子文件)
apply 179B
build 707B
strip-json-comments.cmd 200B
shjs.cmd 180B
default.css 0B
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
.DS_Store 6KB
Updater.exe 82KB
loading.gif 38KB
loading_cloudspace.gif 27KB
loading_cloudspace.gif 27KB
waiting@2x.gif 8KB
waiting.gif 5KB
.gitattributes 67B
Attributes.html 503B
mui html.html 374B
index.html 270B
index.html 170B
default.html 117B
Basic.html 76B
empty.html 0B
hbuilder.ico 98KB
jshint-rhino.js 1.01MB
jshint.js 1.01MB
out.js 556KB
index.js 397KB
non-ascii-identifier-start.js 278KB
beautifier.js 215KB
jshint.js 151KB
beautify.js 146KB
beautify-html.js 109KB
beautifier.min.js 102KB
jquery-3.4.1.min.js 86KB
extension.js 61KB
beautifier.js 55KB
beautify-css.js 53KB
lex.js 47KB
semver.js 38KB
options.js 36KB
validate.js 35KB
cli.js 35KB
beautifier.js 34KB
snippetController.js 34KB
sbcs-data-generated.js 31KB
adm-zip.js 30KB
fnmatch.js 30KB
scope-manager.js 29KB
index.js 27KB
zepto.min.js 26KB
_stream_readable.js 25KB
Tokenizer.js 25KB
minimatch.js 25KB
minimatch.js 25KB
cli.js 24KB
cli.js 24KB
dbcs-codec.js 23KB
cli.js 21KB
vars.js 20KB
glob.js 19KB
glob.js 19KB
tokenizer.js 19KB
hjson.min.js 17KB
hjson.min.js 17KB
tests.js 15KB
beautifier.js 15KB
zipFile.js 13KB
_stream_writable.js 13KB
output.js 12KB
nopt.js 12KB
sync.js 12KB
sync.js 12KB
zipEntry.js 12KB
tokenizer.js 11KB
snippetParser.js 11KB
entryHeader.js 11KB
range.js 11KB
index.js 11KB
messages.js 11KB
index.js 10KB
snippet.js 10KB
utf32.js 10KB
acorn.js 10KB
dbcs-data.js 9KB
utf7.js 9KB
template.js 9KB
old.js 8KB
old.js 8KB
non-ascii-identifier-part-only.js 8KB
Parser.js 8KB
index.js 8KB
utils.js 8KB
templatablepattern.js 7KB
_stream_transform.js 7KB
yallist.js 7KB
index.js 7KB
extension.js 7KB
bench.js 7KB
options.js 7KB
共 2004 条
- 1
- 2
- 3
- 4
- 5
- 6
- 21
资源评论
bxhifeiofheiowd
- 粉丝: 0
- 资源: 1
上传资源 快速赚钱
- 我的内容管理 展开
- 我的资源 快来上传第一个资源
- 我的收益 登录查看自己的收益
- 我的积分 登录查看自己的积分
- 我的C币 登录后查看C币余额
- 我的收藏
- 我的下载
- 下载帮助
安全验证
文档复制为VIP权益,开通VIP直接复制
信息提交成功