js-prettify
Version:
An up-to-date version of js-beautify for Assemble's helpers.
59 lines (58 loc) • 9.4 kB
JSON
{
"name": "js-prettify",
"version": "1.4.0",
"description": "An up-to-date version of js-beautify for Assemble's helpers.",
"main": "js/index.js",
"bin": {
"css-beautify": "./js/bin/css-beautify.js",
"html-beautify": "./js/bin/html-beautify.js",
"js-beautify": "./js/bin/js-beautify.js"
},
"directories": {
"lib": "js/lib",
"test": "js/test"
},
"scripts": {
"test": "./js/test/shell-smoke-test.sh && node ./js/test/node-beautify-tests.js",
"update-codemirror": "npm install codemirror && rm -rf ./web/third-party/codemirror/* && cp ./node_modules/codemirror/LICENSE ./web/third-party/codemirror/ && cp ./node_modules/codemirror/README.md ./web/third-party/codemirror/ && cp -r ./node_modules/codemirror/lib ./web/third-party/codemirror/ && mkdir -p ./web/third-party/codemirror/mode && cp -r ./node_modules/codemirror/mode/javascript ./web/third-party/codemirror/mode/ && git add -Av ./web/third-party/codemirror"
},
"bugs": {
"url": "https://github.com/psyrendust/js-prettify/issues"
},
"homepage": "https://github.com/psyrendust/js-prettify",
"repository": {
"type": "git",
"url": "git://github.com/psyrendust/js-prettify.git"
},
"keywords": [
"helper",
"helper prettify",
"prettify",
"beautify",
"code formatter",
"code formatting",
"formatter",
"formatting",
"beautifier",
"prettifier",
"code-quality"
],
"licenses": [
{
"type": "MIT",
"url": "https://github.com/helpers/prettify/blob/master/LICENSE-MIT"
}
],
"dependencies": {
"config-chain": "~1.1.5",
"mkdirp": "0.3.5",
"nopt": "~2.1.1"
},
"devDependencies": {
"jshint": "1.1.0"
},
"readme": "# JS Beautifier\r\n[](http://travis-ci.org/einars/js-beautify)\r\n[](http://badge.fury.io/js/js-beautify)\r\n\r\nThis little beautifier will reformat and reindent bookmarklets, ugly\r\nJavaScript, unpack scripts packed by Dean Edward’s popular packer,\r\nas well as deobfuscate scripts processed by\r\n[javascriptobfuscator.com](http://javascriptobfuscator.com/).\r\n\r\n# Usage\r\nYou can beautify javascript using JS Beautifier in your web browser, or on the command-line using node.js or python.\r\n\r\n## Web Browser\r\nOpen [jsbeautifier.org](http://jsbeautifier.org/). Options are available via the UI.\r\n\r\n## Python\r\nTo beautify using python:\r\n\r\n```bash\r\n$ pip install jsbeautifier\r\n$ js-beautify file.js\r\n```\r\n\r\nBeautified output goes to `stdout`.\r\n\r\nTo use `jsbeautifier` as a library is simple:\r\n\r\n``` python\r\nimport jsbeautifier\r\nres = jsbeautifier.beautify('your javascript string')\r\nres = jsbeautifier.beautify_file('some_file.js')\r\n```\r\n\r\n...or, to specify some options:\r\n\r\n``` python\r\nopts = jsbeautifier.default_options()\r\nopts.indent_size = 2\r\nres = jsbeautifier.beautify('some javascript', opts)\r\n```\r\n\r\n## JavaScript\r\n\r\nAs 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.\r\n\r\n```bash\r\n$ npm -g install js-beautify\r\n$ js-beautify foo.js\r\n```\r\n\r\nYou can also use `js-beautify` as a `node` library (install locally, the `npm` default):\r\n\r\n```bash\r\n$ npm install js-beautify\r\n```\r\n\r\n```js\r\nvar beautify = require('js-beautify').js_beautify,\r\n fs = require('fs');\r\n\r\nfs.readFile('foo.js', 'utf8', function (err, data) {\r\n if (err) {\r\n throw err;\r\n }\r\n console.log(beautify(data, { indent_size: 2 }));\r\n});\r\n```\r\n\r\n## Options\r\n\r\nThese are the command-line flags for both Python and JS scripts:\r\n\r\n```text\r\nCLI Options:\r\n -f, --file Input file(s) (Pass '-' for stdin)\r\n -r, --replace Write output in-place, replacing input\r\n -o, --outfile Write output to file (default stdout)\r\n --config Path to config file\r\n --type [js|css|html] [\"js\"]\r\n -q, --quiet Suppress logging to stdout\r\n -h, --help Show this help\r\n -v, --version Show the version\r\n\r\nBeautifier Options:\r\n -s, --indent-size Indentation size [4]\r\n -c, --indent-char Indentation character [\" \"]\r\n -l, --indent-level Initial indentation level [0]\r\n -t, --indent-with-tabs Indent with tabs, overrides -s and -c\r\n -p, --preserve-newlines Preserve line-breaks (--no-preserve-newlines disables)\r\n -m, --max-preserve-newlines Number of line-breaks to be preserved in one chunk [10]\r\n -P, --space-in-paren Add padding spaces within paren, ie. f( a, b )\r\n -j, --jslint-happy Enable jslint-stricter mode\r\n -b, --brace-style [collapse|expand|end-expand] [\"collapse\"]\r\n -B, --break-chained-methods Break chained method calls across subsequent lines\r\n -k, --keep-array-indentation Preserve array indentation\r\n -x, --unescape-strings Decode printable characters encoded in xNN notation\r\n -w, --wrap-line-length Wrap lines at next opportunity after N characters [0]\r\n -X, --e4x Pass E4X xml literals through untouched\r\n --good-stuff Warm the cockles of Crockford's heart\r\n```\r\n\r\nThese largely correspond to the underscored option keys for both library interfaces, which have these defaults:\r\n\r\n```json\r\n{\r\n \"indent_size\": 4,\r\n \"indent_char\": \" \",\r\n \"indent_level\": 0,\r\n \"indent_with_tabs\": false,\r\n \"preserve_newlines\": true,\r\n \"max_preserve_newlines\": 10,\r\n \"jslint_happy\": false,\r\n \"brace_style\": \"collapse\",\r\n \"keep_array_indentation\": false,\r\n \"keep_function_indentation\": false,\r\n \"space_before_conditional\": true,\r\n \"break_chained_methods\": false,\r\n \"eval_code\": false,\r\n \"unescape_strings\": false,\r\n \"wrap_line_length\": 0\r\n}\r\n```\r\n\r\nIn addition to CLI arguments, you may pass config to the JS executable via:\r\n\r\n * any `jsbeautify_`-prefixed environment variables\r\n * a `JSON`-formatted file indicated by the `--config` parameter\r\n * a `.jsbeautifyrc` file containing `JSON` data at any level of the filesystem above `$PWD`\r\n\r\nConfiguration sources provided earlier in this stack will override later ones.\r\n\r\nYou 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!\r\n\r\n### CSS & HTML\r\n\r\nIn 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.\r\n\r\n```js\r\n// Programmatic access\r\nvar beautify_js = require('js-beautify'); // also available under \"js\" export\r\nvar beautify_css = require('js-beautify').css;\r\nvar beautify_html = require('js-beautify').html;\r\n\r\n// All methods accept two arguments, the string to be beautified, and an options object.\r\n```\r\n\r\nThe CSS & HTML beautifiers are much simpler in scope, and possess far fewer options.\r\n\r\n```text\r\nCSS Beautifier Options:\r\n -s, --indent-size Indentation size [4]\r\n -c, --indent-char Indentation character [\" \"]\r\n\r\nHTML Beautifier Options:\r\n -I, --indent-inner-html Indent <head> and <body> sections. Default is false.\r\n -s, --indent-size Indentation size [4]\r\n -c, --indent-char Indentation character [\" \"]\r\n -b, --brace-style [collapse|expand|end-expand] [\"collapse\"]\r\n -S, --indent-scripts [keep|separate|normal] [\"normal\"]\r\n -w, --wrap-line-length Maximum characters per line (0 disables) [250]\r\n -p, --preserve-newlines Preserve existing line-breaks (--no-preserve-newlines disables)\r\n -m, --max-preserve-newlines Maximum number of line-breaks to be preserved in one chunk [10]\r\n -U, --unformatted List of tags (defaults to inline) that should not be reformatted\r\n```\r\n\r\n# License\r\n\r\nYou are free to use this in any way you want, in case you find this\r\nuseful or working for you but you must keep the copyright notice and license. (MIT)\r\n\r\n# Credits\r\n\r\n* Written by Einar Lielmanis, <einar@jsbeautifier.org>\r\n* Python version flourished by Stefano Sanfilippo <a.little.coder@gmail.com>\r\n* General maintenance and expansion by Liam Newman <bitwiseman@gmail.com>\r\n* Command-line for node.js by Daniel Stockman <daniel.stockman@gmail.com>\r\n\r\nThanks also to Jason Diamond, Patrick Hof, Nochum Sossonko, Andreas Schneider, Dave\r\nVasilevsky, Vital Batmanov, Ron Baldwin, Gabriel Harrison, Chris J. Shull,\r\nMathias Bynens, Vittorio Gambaletta and others.\r\njs-beautify@1.3.4\r\n\r\n",
"readmeFilename": "README.md",
"_id": "js-prettify@1.4.0",
"_from": "js-prettify@~1.4.0"
}