Javascript source code generation

There is a js file with a lot of code in an unreadable format (all code in one line): JS file

Is there a formatting tool in the "normal" view?

0
source share
4 answers

Developer tools built into most modern browsers can clear formatting. As an example, below is an animated GIF showing how you can achieve this in Microsoft Edge:

enter image description here

Similar functionality exists for both Chrome and Firefox .

There are also online solutions if you want to copy / paste a large block of mini-code.

0
source

Brian Agnew's link should work fine. There's also a standalone Polystyle that I can recommend (costs $ 15, though).

On the other hand, you might be better off getting the TinyMCE non-minified version and working with it first. Some minifiers not only remove line breaks, but also change variable names and other code elements.

+2
source

Most JavaScript engines decorate functions. Knowing this, here is a function that can help you solve your problem:

function beautify (code) { return new Function(code).toString(0) .replace(/^function\s*\w*\s*\(\s*\)\s*{?|;?}?$/g, "") .replace(/\n\s{4}/g, "\n").replace(/^\n/, "") } 

SpiderMonkey and Rhino may also not decorate (reduce) them if you use function.toString(-1) , if you ever need to do the opposite. I also have a function for this:

 function minify (code) { new Function(code).toString(-1) .replace(/^function\s*\w*\s*\(\s*\)\s*{?|;?}?$/g, ""); } 

Edit: It seems you only need to do this for tinymce.js. You can download TinyMCE source code as an open source.

+1
source

Also take a look at this: http://closure-compiler.appspot.com/home ; Google Tool

Select [Enough Print] under "Formatting"

0
source

All Articles