Pretty Fast is a source-map-generating JavaScript pretty printer, used by the Firefox Developer Tools debugger.
Перейти к файлу
Nicolas Chevobbe 9f55fff7f5
Merge pull request #53 from nchevobbe/node-12
Directly require acorn instead of a specific file
2021-06-11 14:27:57 +02:00
.circleci Switch to jest (#38) 2020-03-10 15:47:12 -05:00
__snapshots__ Fix pretty printing of expression with private fields. 2021-05-11 08:44:41 +02:00
bin Add license blocks to the top of each file. 2013-11-04 13:03:02 -08:00
.eslintrc Switch to jest (#38) 2020-03-10 15:47:12 -05:00
.gitignore Initial commit 2013-10-31 15:59:08 -07:00
CODE_OF_CONDUCT.md Add Mozilla Code of Conduct file 2019-03-27 21:21:02 -07:00
LICENSE.md Initial commit 2013-10-31 15:59:08 -07:00
README.md Add an ecmaVersion option that will be passed to acorn. 2021-05-06 13:48:01 +02:00
package-lock.json Update acorn to get support for private field 2021-05-10 07:15:54 +02:00
package.json Update version to 0.2.7 2021-06-11 14:25:50 +02:00
pretty-fast.js Require acorn directly instead of a specific file. 2021-06-11 13:39:26 +02:00
test.js Fix pretty printing of expression with private fields. 2021-05-11 08:44:41 +02:00

README.md

Pretty Fast

Pretty Fast is a source-map-generating JavaScript pretty printer, that is pretty fast.

Build Status

Install

npm install pretty-fast

Usage

var prettyFast = require("pretty-fast");

var uglyJS = "function ugly(){code()}";

var pretty = prettyFast(uglyJS, {
  url: "test.js",
  indent: "  "
});

console.log(pretty.code);
// function ugly() {
//   code()
// }

console.log(pretty.map);
// [object SourceMapGenerator]

(See the mozilla/source-map library for information on SourceMapGenerator instances, and source maps in general.)

Options

  • url - The URL of the JavaScript source being prettified. Used in the generated source map. If you are prettifying JS that isn't from a file or doesn't have a URL, you can use a dummy value, such as "(anonymous)".

  • indent - The string that you want your code indented by. Most people want one of " ", " ", or "\t".

  • ecmaVersion - Indicates the ECMAScript version to parse. See acorn.parse documentation for more details. Defaults to "latest".

Issues

Please use Bugzilla

Goals

  • To be pretty fast, while still generating source maps.

  • To avoid fully parsing the source text; we should be able to get away with only a tokenizer and some heuristics.

  • Preserve comments.

  • Pretty Fast should be able to run inside Web Workers.

Non-goals

  • Extreme configurability of types of indentation, where curly braces go, etc.

  • To be the very fastest pretty printer in the universe. This goal is unattainable given that generating source maps is a requirement. We just need to be Pretty Fast.

  • To perfectly pretty print exactly as you would have written the code. This falls out from both not wanting to support extreme configurability, and avoiding full on parsing. We just aim to pretty print Pretty Well.