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.