April 4th, 2006

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/Bookmark

3 Responses to ' Clean Up Your JavaScript '

Subscribe to comments with RSS or TrackBack to ' Clean Up Your JavaScript '.

  1. Mali said,

    on December 11th, 2008 at 11:30 am

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

    Mali

  2. Dutchflyboy said,

    on February 15th, 2009 at 10:32 am

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


  3. on March 17th, 2009 at 9:07 am

    [...] 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/ [...]

Leave a reply

*
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.
Click to hear an audio file of the anti-spam word