To satisfy your reverse-engineering cravings: a free online Javascript beautifier

Lately in my day job I've been troubleshooting ASP.NET pages that use server controls that lean heavily on Javascript.  The kind of Javascript that is stripped and streamlined with zero whitespace or carriage returns.  So to make any sense of it at all I needed a beautifier:

function layoutmouseup() {if ((moving != 0) && (target != 0)) {rearrange(moving, movingcol, target, targetcol);var targ = target;if (movingcol == targetcol && target > moving) {targ = targ - 1;}displaylayout();}moving = 0;movingcol = 0;target = 0;targetcol = 0;}
function layoutmouseup()
{
	if ((moving != 0) && (target != 0))
	{
		rearrange(moving, movingcol...
		var targ = target;
		if (movingcol == targetcol ...
		{
			targ = targ - 1;
		}
		displaylayout();
	}
moving = 0; movingcol = 0; target = 0; targetcol = 0; }
 

After Googling for “javascript beautifier free” I came up with only payware solutions that have more features than I wanted.  I just want a simple way to put crappy Javascript in, and get back stuff that looks reminiscent to the C# I write in Visual Studio.  So I took a half hour and wrote a free beautifier:

http://couponmeister.com/beautify.aspx

Source code is available from the link if you'd like to extend it.  Will work with Java, C++, and C# as well.

Enjoy!

UPDATE: A more recent post about the beautifier is available here.


Feedback

# Thanks !

Great job, and really useful to me today ! :) 3/27/2006 8:39 PM | Xavier

# Thank you VERY much !

I had to debug a one-line file (3000 caracters). This has been VERY useful. Thanks ! 4/17/2006 8:41 AM | Didier

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier

Looks good but it's not currently capturing for-loops, for example:

for(j=1;j<2;j++){doSomething(i);}

At the moment it's splitting the for-loop declaration into several lines due to the semi-colons. 5/15/2006 12:06 AM | Alex

# A few bugs are now fixed

Alex -- Good call on the for() loop issue. I have just fixed that. Also an issue with single vs double quotes around strings. So it's much more reliable now. Plus I converted to using StringBuilder instead of simple string concatenation, and large blocks of script now parse much more quickly.

This will always remain 100% free and open-source. Please tell your friends or blog about it. 7/17/2006 7:21 AM | Lorin

# Also handles obfuscation

One more thing I forgot to mention -- the routine now handles escaped characters that are represented in hexadecimal or octal. So some of the gnarlier obfuscated strings can be made more readable. You're stuck with the crazy variable names though. To clean those up you would have to have a pretty smart parser that knows the scope of variables and can rename them in just the right places.
7/17/2006 8:55 AM | Lorin

# translated to JavaScript/PSPad

I wanted to use the beautifier in the PSPad editor, so I translated the cs-code to JavaScript:

http://triess.de/download/format.zip
7/17/2006 11:49 AM | Stefan Triess

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier

Link broken :-( 8/15/2006 12:54 PM | Pete

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier

it doesn't handle comments 9/16/2006 3:16 PM | andy

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier

Great stuff, thx a million mate! 11/28/2006 10:44 AM | Hamayoun

# Thank you!!

It is a great tool to form the code!! 12/30/2006 1:10 AM | Jan

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier

Thanks so much - This is just what I needed! 1/23/2007 9:40 PM | SquadraCorse

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier

Code like this
// A line with comment
setTimeout('bbb()',100);
setTimeout("cccc(0)", 100);

becomes:
// A line with comment setTimeout('bbb()',100); setTimeout("cccc(0)", 100);
6/15/2007 6:53 AM | Desislav Kamenov

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier

where's the source code??? i need your help plz 7/19/2007 11:00 AM | Jore

# Crashes on AdSense

This code gives a "Index was outside the bounds of the array" error.

http://pagead2.googlesyndication.com/pagead/show_ads.js
10/16/2007 9:38 AM | David Phillips

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier

Greate job!
But the source code can't download!
Can please check out the link:
http://hdvforever.com/blog/beautifier.zip 1/20/2008 12:12 AM | Jim

# Got an exception with code menu.js

[IndexOutOfRangeException: Index was outside the bounds of the array.]
System.Text.StringBuilder.get_Chars(Int32 index) +20
beautifier.beautify.endsWith(StringBuilder dst, String check)
beautifier.beautify.doBeautify_Click(Object sender, EventArgs e)
System.Web.UI.WebControls.Button.OnClick(EventArgs e) +108
System.Web.UI.WebControls.Button.System.Web.UI.IPostBackEventHandler.RaisePostBackEvent(String eventArgument) +57
System.Web.UI.Page.RaisePostBackEvent(IPostBackEventHandler sourceControl, String eventArgument) +18
System.Web.UI.Page.RaisePostBackEvent(NameValueCollection postData) +33
System.Web.UI.Page.ProcessRequestMain() +1292 3/26/2008 9:07 AM | Rayshi02

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier

Source code link zip file doesn't work ;) 12/19/2008 6:08 AM | Mehzoh

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier

Lately in my day job I've been troubleshooting ASP.NET pages that use server controls that lean heavily on Javascript. The kind of Javascript that is stripped and streamlined with zero whitespace or carriage returns. So to make any sense of it at all I needed a beautifier: 8/12/2009 9:20 AM | ed hardy swimwear

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier

ASP.NET is rather dificul tolearn, the source code link zip file wont work 9/22/2009 11:08 AM | Babysitting services

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier

the source code link zip file wont work 10/17/2009 11:50 PM | Tiffany Bracelets

# ed hardy shop

This is just what I needed! 10/23/2009 3:19 AM | ed hardy

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier

very help dul aritvl 11/1/2009 4:23 PM | Watch Animes Online

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier

Thanks for the post mate! Great share.
pet meds 11/3/2009 11:25 AM | Janna

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier

Lorin, thanks for that one! 11/6/2009 11:33 PM | DDos Protection

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier

the source code link zip file wont work 11/11/2009 6:41 AM | tiffany and co

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier

Thank you very much. Very helpeful. 11/15/2009 9:28 AM | sms kostenlos

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier


Nice post,thank you for your sharing.

Frank Gehry has designed and lent his name to this line of
tiffany sterling silver that

includes frank gehry bracelet,frank gehry tiffany rings, necklaces, earrings, cuff links

and more.
11/17/2009 9:45 PM | tiffany necklaces

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier

Thanks for the post mate!
Detox Center 11/27/2009 1:21 PM | GerryG

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier

Late at night.metin2 yang A dream. 11/30/2009 9:28 PM | aion kinah

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier

I converted to using StringBuilder instead of simple string concatenation, and large blocks of script now parse much more quickly.
Places to Visit in Phoenix 12/7/2009 6:32 PM | paul

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier

Well Formatting javascript code is not easy.Visual studio 2008 supports javascript code formatting.
Alcohol Rehab Program Seattle Washington 12/9/2009 10:07 AM | Law

# No javascript , us Jquery

It's better to to take health insurance as soon as possible. Generic Zoloft 12/17/2009 12:38 AM | Buy Lasix online

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier

So some of the gnarlier obfuscated strings can be made more readable. You're stuck with the crazy variable names though. To clean those up you would have to have a pretty smart parser that knows the scope of variables and can rename them in just the right places.
Statute Of Limitations Malpractice 12/21/2009 12:58 PM | paul

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier

There are several reasons but to me the most important is that Bing does not associate your search data with your other Microsoft accounts to build a rich and personally identifying profile of you.
Cheap Nexium 12/23/2009 6:20 AM | Mariya

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier

So some of the gnarlier obfuscated strings can be made more readable. You're stuck with the crazy variable names though. To clean those up you would have to have a pretty smart parser that knows the scope of variables and can rename them in just the right places. watch love happens online | harry potter and the half blood prince watch online 12/23/2009 8:13 AM | watch inglourious basterds

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier

we like a number of the stuff you have put online about snitterfield like the virtual village. they have started a project of building a village site for snitterfield which you might require to contribute some material or perhaps link back to us from your web pages 12/23/2009 4:10 PM | drept penal

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier

25 Feb 2006 ... re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier. very help dul aritvl 11/1/2009 4:23 PM | Watch Animes ...
Road Trip Planner
towe Ski
12/24/2009 2:06 PM | sidkof

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier

26 May 2009 ... Coriell Personalized Medicine Collaborative Launches Web Portal. from Business ... The Personalized Medicine Coalition (PMC) released the ...
Road Trip Planner
towe Ski
12/24/2009 2:14 PM | juliajin

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier

Plus I converted to using StringBuilder instead of simple string concatenation, and large blocks of script now parse much more quickly. 12/30/2009 7:45 PM | brand clothing

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier

Great job but i did use this script in my apps but not be working well. 1/6/2010 2:33 PM | elottery

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier

can we use these scripts into Facebooks apps 1/11/2010 12:18 AM | Marketing For Dentists

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier

can we use for the face apps 1/11/2010 4:01 PM | No Prescription Online Pharmacy

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier

JavaScript Beautifier reformats JavaScript source code to make it more readable. Code beautification involves parsing the JavaScript source code into component structures, such as assignment statements, if blocks, loops, etc., and formatting them in a proper manner. It is quick, easy and free! 1/12/2010 6:36 AM | Cheap Lasix

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier

Plus I converted to using StringBuilder instead of simple string concatenation, and large blocks of script now parse much more quickly. 1/13/2010 1:10 PM | Online Dating

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier

if blocks, loops, etc., and formatting them in a proper manner. It is quick, easy and free! 1/14/2010 2:26 AM | UGG Classic Tall Boots

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier

JavaScript Beautifier reformats JavaScript source code to make it more readable. Code beautification involves parsing the JavaScript source code into component structures, such as assignment statements, if blocks, loops, etc., and formatting them in a proper manner. It is quick, easy and free! better off ted season 2 episode 7 | ncis: los angeles season 1 episode 11 1/15/2010 3:49 AM | bad girls club season 4 episode

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier

such as assignment statements, if blocks, loops, etc., and formatting them in a proper manner. It is quick, easy and free 1/17/2010 8:45 PM | bailey button ugg

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier

Great job and very much thrilling as well. 1/18/2010 1:49 AM | send flower to Russia

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier

Nice code.. We have many source codes in our website.. Feel free to read them all.... 1/18/2010 9:54 AM | Ecommerce development

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier

Use javascript is very important, although you need always taking care of those who don't have javascript allowed in their browser... 1/18/2010 9:57 AM | debt consolidation loans

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier

Thanks for your great tip 1/20/2010 3:00 AM | Watch Anime Online

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier

well worth the read. thank you very much for taking the time to share with those who are starting on the subject. Greetings
1/25/2010 2:48 PM | Online Sports Betting

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier

Thanks for the consecutive thing as well. 1/26/2010 7:41 AM | Pharmacy No Prescription

# Cheap UGG Boots & UGG Boots Sale Best Outlet Online Store offer genuine natural sheepskin boots.

My friend, Ric*, and I love to go shopping together and getting 1/30/2010 1:04 AM | ugg boots sale

# re: To satisfy your reverse-engineering cravings: a free online Javascript beautifier

i think you have forgotten to add source code. please add this to solve my problem.
Thanks.
2/2/2010 2:59 PM | loose diamonds

Post a comment





 

News


Welcome to my blog.
Here's what we've got on the menu today:

Tag Cloud


Article Categories

Archives

Post Categories

Image Galleries

Syndication: