7 Jan 2009

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.

Add Your Comment

Spam Protection by WP-SpamFree

Quick and dirty way to indent JS files

  1. Aptana (http://www.aptana.com/) has a great format feature as well as real-time JavaSCript syntax checking and it’s free.

    Also, if you have Flash 8, you can copy JS into the actions panal and hit the autoformat button and get some pleasing results. Flash CS3 has a horribly broken autoformat, so I don’t recommend EVER using it.

    Greg Ferrell
  2. And if you have TextMate handy, then JavaScript bundle comes with Reformat Document command.

    Erki Esken
  3. Pretty sure Dreamweaver can do this too – not as clean as a comand-shell call but gets the same outcome

    pete