# JS Beautifier

[](https://pypi.python.org/pypi/jsbeautifier)
[](https://cdnjs.com/libraries/js-beautify)
[](https://www.npmjs.com/package/js-beautify)
[](https://www.npmjs.com/package/js-beautify?activeTab=versions)
[](https://gitter.im/beautify-web/js-beautify?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge)
[](https://twitter.com/intent/user?screen_name=js_beautifier)
[](https://www.npmjs.org/package/js-beautify) [](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.3.6.5.20221121.zip
需积分: 0 26 浏览量
更新于2022-11-25
1
收藏 32.38MB ZIP 举报
《HBuilderX:新一代的HTML开发利器》
HBuilderX,这个名字源于HTML的首字母“H”和“Builder”的组合,X则代表了这个工具的进化版,是HBuilder的下一代产品,通常简称为HX。它不仅仅是一款编辑器,更是一款功能强大的集成开发环境(IDE),集轻便与强大于一身,为前端开发者提供了前所未有的高效开发体验。
HBuilderX的核心理念在于提升开发效率。在HTML、CSS、JavaScript等前端技术日新月异的今天,开发者需要一个能够快速响应变化、提供智能辅助的工具。HBuilderX正是这样一款工具,它拥有丰富的代码提示、自动补全、语法高亮、实时预览等特性,使得编写前端代码变得更为轻松快捷。
1. **代码智能提示与补全**:HBuilderX内置了全面的HTML、CSS、JavaScript语法规则库,无论是在创建新的元素、属性,还是编写复杂的JavaScript逻辑,都能享受到即时的智能提示,极大地减少了手动查找和输入的时间,提升了开发速度。
2. **实时预览与调试**:HBuilderX支持实时预览功能,修改代码后无需保存,页面会立即更新,便于开发者观察效果并进行调整。同时,它还提供了强大的调试工具,可以对JavaScript代码进行断点调试,方便定位和解决问题。
3. **项目管理与协作**:HBuilderX具有完善的项目管理功能,可以方便地管理多个项目,支持Git等版本控制工具,使得团队协作更为流畅。此外,它还集成了阿里云上传、下载服务,方便开发者进行代码的云端存储和同步。
4. **插件生态与自定义扩展**:HBuilderX允许用户安装和开发自定义插件,进一步扩展其功能,满足个性化需求。丰富的第三方插件生态系统,使得HBuilderX能够适应各种开发场景,提高开发效率。
5. **多语言与跨平台**:HBuilderX支持Windows、Mac OS以及Linux等主流操作系统,满足不同开发者的使用习惯。同时,它还支持多种语言环境,方便国际化开发。
6. **性能优化**:HBuilderX以其优秀的性能著称,无论是启动速度、内存占用,还是代码编译、文件搜索等方面,都表现出极高的效率,确保了开发过程的流畅性。
7. **Vue、React、Angular等框架支持**:HBuilderX特别优化了对当前流行的前端框架的支持,如Vue.js、React.js、Angular等,提供便捷的模板创建和代码片段,让框架开发更加得心应手。
通过以上特性,HBuilderX成为了众多前端开发者首选的开发工具。无论你是初学者还是资深开发者,都能在HBuilderX中找到适合自己的工作流,实现高效的HTML、CSS、JavaScript编码。随着版本的不断迭代和更新,HBuilderX将继续引领前端开发工具的发展潮流,为开发者带来更多的便利和创新。

qxmjava
- 粉丝: 25
最新资源
- 软件项目验收申请单(1).docx
- 基于双创型人才培养的互联网+教育变革研究(1).docx
- 浅析办公自动化中的计算机技术应用及发展(1).docx
- 基于PLC的多种液体混合控制系统设计(1).doc
- 浅论机械自动化技术及在我国的发展-毕业论文设计(1).doc
- 中小企业电子商务发展缺陷与策略(1).docx
- 大数据云计算环境下的数据安全(1).docx
- 论人工智能时代高等教育改革(1).docx
- 数控编程练习题(1).docx
- 计算机网络安全及对策(1).docx
- 大数据时代信息通信技术应用(1).docx
- 计算机实训室安全操作规程(2)(1).doc
- 信息化在建筑工程管理中的运用1(1).docx
- 浅谈软件项目管理三大追求(1).docx
- 【推荐】软件开发项目成本研究(1).doc
- OracleERP项目系统操作培训财务总帐(1).pptx