Tool to Unminify / Decompress JavaScript [closed]

2019-01-01 09:57发布

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.)

17条回答
梦醉为红颜
2楼-- · 2019-01-01 10:04

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.

查看更多
泛滥B
3楼-- · 2019-01-01 10:04

Similar to Stone's answer, but for Windows/.NET developers:

If you have Visual Studio and ReSharper - An easy alternative for formatting Javascript is:

  • Open the file with Visual Studio;
  • Click on ReSharper > Tools > Cleanup Code (Ctrl+E, C);
  • Select "Default: Reformat code", and click OK;
  • Crack open a beer.
查看更多
流年柔荑漫光年
4楼-- · 2019-01-01 10:05

As an alternative (since I didn't know about jsbeautifier.org until now), I have used a bookmarklet that reenabled the decode button in Dean Edward's Packer.

I found the instructions and bookmarklet here.

here is the bookmarklet (in case the site is down)

javascript:for%20(i=0;i<document.forms.length;++i)%20{for(j=0;j<document.forms[i].elements.length;++j){document.forms[i].elements[j].removeAttribute(%22readonly%22);document.forms[i].elements[j].removeAttribute(%22disabled%22);}}
查看更多
只若初见
5楼-- · 2019-01-01 10:05

http://unminify.appspot.com/ Great tools for unminify javascript and json

查看更多
时光乱了年华
6楼-- · 2019-01-01 10:10

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.
查看更多
听够珍惜
7楼-- · 2019-01-01 10:14

Most of the IDEs also offer auto-formatting features. For example in NetBeans, just press CTRL+K.

查看更多
登录 后发表回答