You are hereBlogs / rahul's blog / - Javascript beautifier in .Net - Javascript beautifier in .Net

rahul's picture

By rahul - Posted on 20 December 2010

I finally got fed-up today with having to use online javascript beautifiers whenever I needed to re-format a minified javascript file to make it readable. I often need to reformat a minified script to have a look at some part of it and thought it would be great if a utility can quickly format the script through command-line.

So, I went out today searching for such a utility supporting command-line mode of operation for the beautification process. However everything I came across provided an online option for beautification (optionally with the source code, that could be used offline also from the local machine). But none supported the command-line way of doing things I was looking for. So, I decided to use one of the existing beautification utilities and create a wrapper for it supporting both interactive as well as command-line mode.

I found js-beautify ( a popular utility for the task and decided to use it to create my wrapper for the command-line. Although the beautifier itself ships with various ways of executing it from the command-line, but all those ways needed (a bit hefty) installations and configuration, before you can use them from the command-line.

I ended up creating ( is a simple wrapper created in .NET 2.0 for js-beautify. js-beautify does all its work in javascript and provides some handy options to control the format of the beautified script. My .Net wrapper allows you regular interactive access with exactly the same User Interface as the original beautifier.

But additionally, it supports a zero-configuration command-line mode for automating the beautification tasks from command-line. An example command-line invocation of the wrapper is as follows: "sourceFile=C:\TextToJs.txt" "destinationFile=C:\TextToJs1.txt" "indent=2" "bracesInNewLine=false" "preserveEmptyLines=true" "detectPackers=false" "keepArrayIndent=false"

The attached file contains examples of executing from regular command line we well as from PowerShell, together with the full source and binary for the

The wrapper supports all options of the original js-beautify to be passed as command-line parameters.

It has been created in .NET 2.0 (and has no external dependency that you need to download separately), so should readily run in all versions of Windows supported by .Net 2.0 (i.e. Windows 98 and later). If you are on Windows Vista or later, you only need to download the attached file(Vista and later come with .Net 2.0) and run with appropriate parameters from command-line or execute it as a normal Desktop application for interactive use. Windows XP and earlier users might need to verify if they have .NET 2.0 installed, and would need to install it first if not available already.

If you are a Mono user on a non-Windows OS, then would not work for you as it has dependency on components not available in Mono on non-Windows platforms (but should work in Mono on Windows platform although I haven't tested this).

The 1.0 release of this utility is attached with this blog post. To keep up with the changes for this utility, you can watch it on its GitHub page here.



AttachmentSize KB

If I run multiple at the same time from commandline, the program will crash.

Any solutions?

rahul's picture

Hi Le, I haven't really tried that scenario, and owing to my schedule, probably won't be able to.


it is one of the good online editor+beautifier+minifier+validator+image viewer for javascript and other scripting language.........

thanks for that fine commandline tool
realy easy to use - and on the top unique.
there are nearly no windows commandline tools for this kind of work. i use only: "sourceFile=all.json"


rahul's picture

Thanks for the feedback ewer..

Post new comment

The content of this field is kept private and will not be shown publicly.
Type the characters you see in this picture. (verify using audio)
Type the characters you see in the picture above; if you can't read them, submit the form and a new image will be generated. Not case sensitive.

Recent comments