JavaScript Code

Clean Up Your JavaScript

This is a great tool that properly formats JavaScript code, making it easy to read and work with. With it you can clean up your own code, or take code from existing functions (like Dreamweaver behaviours) and decrypt them; inserting line breaks and tabs where it makes sense. Best of all, the tool is free!

This tool is similar to the 'apply source formatting' for HTML in Dreamweaver. It has several options:

  1. Take an input .js file, and output to a new, cleanly formatted file
  2. Open in Notepad
  3. Drag and drop
  4. Switch languages
  5. Insert new line before opening bracket (Visual Studio style)
  6. Insert tabs or spaces

Here's the example code cleanup from the author's website:


<script language="JavaScript">var i=0,s="",k=0;function foo()
{for(j=0;j<10;j++){for(i=0;i<10;i++){s="string1";
k=Math.floor(Math.random()*10);
for(i=20;i>9;i--){s="string2";k=i;}}}</script>

This gets run through the 'JavaScript Code Improver', and becomes:


<script language="JavaScript">
var i = 0, s = "", k = 0;
function foo()
{
    for(j = 0; j < 10; j++)
    {
        for(i = 0; i < 10; i++)
        {
            s = "string1";
            k = Math.floor( Math.random()*10 );
        }
        for(i = 20; i > 9; i--)
        {
            s = "string2";
            k = i;
        }
    }
}
</script>

Much easier to read and work with! You can download the tool for free here. Note: while this tool does clean up and format obfuscated code, it may still be difficult to understand!

Share

5 Comments

  1. I downloaded the app and it works beautiful. Thank you!!

    Mali

  2. It's quite nice but it removes ALL comments, if it wouldn't do that, it would be perfect.

  3. Alexander Makhno’s Blog » TinyMCE3 battle

    […] P.S.: there is an utility "a great tool that properly formats JavaScript code". Very good for formatting files "editor_plugin.js" back for reading: http://www.justin-cook.com/wp/2006/04/04/clean-up-your-javascript/ […]

  4. This tool is awesome, thanks alot for lettung us know there is a tool like this!

  5. I am using this online tool for my js codes, xtreeme.com/javascript-optimizer/ and also checked with jshint.com, very helpful.

Leave a Reply

Your email address will not be published. Required fields are marked *

*
To prove you're a person (not a spam script), type the security word shown in the picture. Click on the picture to hear an audio file of the word.
Anti-spam image