C-indent JavaScript equivalent

Is there a GNU indent for styling C sources, are there any equivalents for JavaScript?

I want it to have options for coding style, indent style, etc., as indent .

I will use it for a rather large project on the * NIX platform, so I don’t like Windows utilities or online tools.

+4
source share
5 answers

Here's a jsBeautifier that can be run from the command line via Rhino in a Java-enabled environment or using V8 (or several others, check out the github page ). They seem to be working on a command line version of Python.

Apparently, someone started (at least) to update indent itself to understand JavaScript . The joy of open source! Even if they are incomplete, the syntax is so similar ... (No, apparently, this is just a web page interface before indent - not useful at all). So rephrase: I wonder how much it would change indent to support JavaScript? The syntaxes are so similar ...

+1
source

I did not use it, but I added js-beautify a while ago, and a quick check seems to indicate that this might suit your requirements. (And, being written in JavaScript, you can probably easily improve it.)

+2
source

You have several options:

Some editors also do this for you:

  • Emacs
  • VI (m)
  • Eclipse
  • ...

edits:

  • Another online tool, JavaScript Indent claims to use Indent in the background. Perhaps the author will share the settings. Not so great, but get started.
  • The JS Beautifier page also mentions that the Python version is evolving as we speak. Please check back later. In the meantime, you can use it with Rhino, as indicated on their page.

Finally, there are already a few answers to questions that you can find by searching (some of the results indicate formatting for displaying code on the Internet, which is different, although you could use it too):

+2
source

There is Javascript Tidy that uses a browser to reformat Javascript code. Thus, the results depend on the browser you are using.

You cannot define a style, but once Javascript has been reformatted to a standard format, it is easier to change the source code to suit your own style.

0
source

libjavascript-beautifier-perl package received /usr/bin/js_beautify , which does the trick for me.

0
source

All Articles