Quick and dirty way to indent JS files

You just got a JS file to work with that's either been minified or really badly indented. What do you do? If you're on OS X or a Linux-based system, fire up Terminal and fire off the indent command:

indent < badly-indented.js > beautiful.js

Since indent is actually meant for C, it may not be perfect but the result should be much easier to read than the original if you're trying to figure out what's going on in the script.

Comments