For formatting, searching, and rewriting javascript.

npm install -g jsfmt
View the source, or read the docs

Formatting to help keep your code neat.

# Format `source.js` and print the results to stdout.
jsfmt source.js

# Format `source.js` and write the results to disk.
jsfmt -w=true source.js

# View a diff of all formatting changes in `source.js` without writing them.
jsfmt -d=true source.js

# List all files that need formatting in the `src/` directory.
# Directories are recursively traversed.
jsfmt -l=true -w=false src/

Searching to smartly find patterns.

# Find all instances of _.reduce() in `source.js`.
# Single letter identifiers act as wildcards, and whitespace is ignored.
jsfmt --search="_.reduce(a, b, c)" source.js

# Find all calls to console.log() in your project's `src/` directory.
jsfmt --search="console.log(s)" src/

Rewriting for easy cleaning and refactoring.

# Replace underscore.js's reduce with the native reduce method in `source.js`.
jsfmt --rewrite="_.reduce(a, b, c) -> a.reduce(b, c)" source.js

# Do it again, but this time save the changes to disk.
jsfmt --write=true --rewrite="_.reduce(a, b, c) -> a.reduce(b, c)" source.js

# Replace modulo with an expression that always returns a positive number, and run the results.
jsfmt --rewrite="x % y -> ((x % y) + y) % y" source.js | node


Built on esprima and esformatter for smart code parsing and formatting. Jsfmt works on your code's AST, not just on its text.

Full API

You can require jsfmt from any node app. Every feature available through the command line is also available through its module. Check our docs for more information.

Active Development

Jsfmt is currently in development, and is constantly changing and improving. Follow along on Github, and feel free to report bugs or request features here.