Tool to Unminify / Decompress JavaScript [closed]

Tool to Unminify / Decompress JavaScript [closed]

Are there any command line scripts and/or online tools that can reverse the effects of minification similar to how Tidy can clean up horrific HTML?
(I’m specifically looking to unminify a minified JavaScript file, so variable renaming might still be an issue.)

Solutions/Answers:

Solution 1:

You can use this : http://jsbeautifier.org/
But it depends on the minify method you are using, this one only formats the code, it doesn’t change variable names, nor uncompress base62 encoding.

edit: in fact it can unpack “packed” scripts (packed with Dean Edward’s packer : http://dean.edwards.name/packer/)

Solution 2:

Chrome developer tools has this feature built-in. Bring up the developer tools (pressing F12 is one way), in the Sources tab, the bottom left bar has a set of icons. The “{}” icon is “Pretty print” and does this conversion on demand.

UPDATE: IE9 “F12 developer tools” also has a “Format JavaScript” feature in the Script tab under the Tools icon there. (see Tip #4 in F12 The best kept web debugging secret)

enter image description here

Solution 3:

Got it! JSBeautifier does exactly this, and you even have options for the auto-formatting.

Solution 4:

Can’t you just use a javascript formatter (http://javascript.about.com/library/blformat.htm) ?

Solution 5:

In Firefox, SpiderMonkey and Rhino you can wrap any code into an anonymous function and call its toSource method, which will give you a nicely formatted source of the function.

toSource also strips comments.

E. g.:

(function () { /* Say hello. */ var x = 'Hello!'; print(x); }).toSource()

Will be converted to a string:

function () {
    var x = "Hello!";
    print(x);
}

P. S.: It’s not an “online tool”, but all questions about general beautifying techniques are closed as duplicates of this one.

Solution 6:

If you have a Mac and TextMate – An easy alternative for formatting Javascript is:

  1. Open the file with Textmate.
  2. Click on > Bundles > JavaScript > Reformat Document
  3. Crack open a beer.