4

I'm looking for a tool that unminifies a JS file, while restoring the variable names in the whole document.

For example, after running the minified code at unminify.com, the code itself contains:

W.find("li.patternItem").click(function() {

and at the end of the code there is a reference defining W:

W = $("#pattern1")

So I am looking for a simple script to restore the name inside the code, but can't find one. I understand the auto replace might be harmful for the code, but I guess that there should be some smart way to restore. Right now I'm doing it manually and replacing "W." with "$("#pattern1")." (match case, with dot at the end) so it won't be mixed with any W letter.

Thanks

Dave Mackey
  • 4,306
  • 21
  • 78
  • 136
Shir Gans
  • 1,976
  • 3
  • 23
  • 40
  • Just to make it clearer: I'm not looking to restore the original variable name, just to have the correct reference along the code. Thanks – Shir Gans Apr 27 '15 at 05:13
  • Did the original code have the reference there? It is likely that the original code simply had `someVar = $("#pattern1");` and `someVar.find("li.patternItem").click(...)`, so this isn't an issue of unminification. – Asad Saeeduddin Apr 27 '15 at 05:15

1 Answers1

26

This tool may help:

http://www.jsnice.org/

This unminifies your js and will make educated guesses as to what the original variables were for and rename them automatically.
It also allows you to replace them in the final code with what you want in an easy way (use interactive renames in the tools menu).

Tims
  • 1,987
  • 14
  • 16