473,405 Members | 2,444 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,405 software developers and data experts.

JavaScript reformatter for Linux?

OK, so I've searched high and low for the answer to this
question. Perhaps there is an answer that I just couldn't
find because it was too hard to filter out the signal from
the noise in the search results.

I want a tool I can install on Linux that will reformat
JavaScript. I've found the javascript-mode that comes with
XEmacs and installed it with no trouble into my GNU Emacs
installation, and I can use that to reindent, but I can't use
that to format the code nicely if, e.g., all the extra
newlines and whitespace were removed to reduce download time
and obfuscate the code. I've also found that GNU indent can
"mostly" indent JavaScript, but it has problems with missing
semicolons, JavaScript string constants bounded by single
quotes instead of double quotes, and JavaScript regular
expressions operators.

So, is there something for Linux specifically designed to
take ugly JavaScript and make it pretty?

Thanks in advance for any help you can provide. And I
apologize if this question has been asked and answered; I
simply can't find the answer, despite looking pretty hard for
it.
Jul 23 '05 #1
6 3261
ji*@kamens.brookline.ma.us (Jonathan Kamens) writes:
I want a tool I can install on Linux that will reformat
JavaScript.


Try Firefox :)
E.g., put this in a page:
---
<script type="text/javascript">
function prettyScript(code) {
try {
var fcode = (new Function(code)).toString();
fcode = fcode.replace(/^\s*function\s+(?:\w+\(\)\s*)?\s*\{\s*\n/, "");
fcode = fcode.replace(/\s*}\s*$/, "");
return fcode;
} catch (e) {
return "SYNTAX ERROR: " + e.message;
}
}
</script>
<form action=""
onsubmit="this.elements.output.value =
prettyScript(this.elements.input.value);
return false;">
<textarea id="input" cols="80" rows="5">"code to format here"</textarea><br>
<input type="submit" value="format"><br>
<textarea name="output" cols="80" rows="10" readonly="readonly">Output here</textarea><br>
</form>
---

Nothing beats a Javascript parser for understanding the syntax of
Javascript :)

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleDOM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 23 '05 #2
Thanks, that's cool, and I suppose I can use it if there are
no other options, but I'm sort of hoping for a CLI-based tool,
not something I have to use through a Web browser.
Jul 23 '05 #3
On Sun, 12 Jun 2005 20:27:55 +0000 (UTC), ji*@kamens.brookline.ma.us
(Jonathan Kamens) wrote:
Thanks, that's cool, and I suppose I can use it if there are
no other options, but I'm sort of hoping for a CLI-based tool,
not something I have to use through a Web browser.


The same code will run in any javascript command line interpreter too

Jim.
Jul 23 '05 #4

Define 'reformat', if you mean a code coloring tool like a syntax
hightlight and such, I use Bluefish and my own regexp custom set for it,
works nice, covers well most objects and many languages not just JS,
though I name my set javascript_1. I'd send you my highlight file for
bluefish with shortcuts and regexps, if that's what you mean. Bluefish
does come with its own set but it isn't so great, fares well though.
Danny
On Sun, 12 Jun 2005 11:30:19 -0700, Jonathan Kamens
<ji*@kamens.brookline.ma.us> wrote:
OK, so I've searched high and low for the answer to this
question. Perhaps there is an answer that I just couldn't
find because it was too hard to filter out the signal from
the noise in the search results.

I want a tool I can install on Linux that will reformat
JavaScript. I've found the javascript-mode that comes with
XEmacs and installed it with no trouble into my GNU Emacs
installation, and I can use that to reindent, but I can't use
that to format the code nicely if, e.g., all the extra
newlines and whitespace were removed to reduce download time
and obfuscate the code. I've also found that GNU indent can
"mostly" indent JavaScript, but it has problems with missing
semicolons, JavaScript string constants bounded by single
quotes instead of double quotes, and JavaScript regular
expressions operators.

So, is there something for Linux specifically designed to
take ugly JavaScript and make it pretty?

Thanks in advance for any help you can provide. And I
apologize if this question has been asked and answered; I
simply can't find the answer, despite looking pretty hard for
it.


--
Using Opera's revolutionary e-mail client: http://www.opera.com/mail/
Jul 23 '05 #5
Danny <da*******@bluebottle.com> writes:
Define 'reformat', if you mean a code coloring tool like a syntax
hightlight and such, I use Bluefish


I'm not familiar with bluefish. What is it?

By "reformat", I mean not just syntax highlighting, but rather
inserting and removing line breaks, whitespace, indentation, etc. in
the code to make it more readable.
Jul 23 '05 #6
ji*@jibbering.com (Jim Ley) writes:
The same code will run in any javascript command line interpreter too


It also discards comments. For my needs, that's a fatal flaw in this
solution.
Jul 23 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

0
by: Robert Freund | last post by:
I've been looking for a good and free code beautifier that runs on linux. About the only ones I found where Trita (www.trita.com), which costs money and only runs on windows. The other one was...
1
by: atodd_109 | last post by:
I currently have a page that is running from a windows based server with frontpage extensions installed. My mouseover script works great. I am now in the process of developing another page that...
9
by: Aaron Gray | last post by:
Hi, I am after a free or open source C++ code reformatter. Basically to change tabs from 3 to 2 and use spaces instead of tabs. And hopefully to neaten up code. Aaron
14
by: Rene Grothmann | last post by:
I have managed to communicate between forms and Java applets. A button press sends the content of the text area to an applet, a second button gets some text from the applet and puts it into the...
3
by: giangiammy | last post by:
as from the subject, anyone has comments about a Javascript IDE for visual programming in Linux environment? thanks giammy
4
by: Lando | last post by:
I'm a bit confused ...javascript and jscript are the same thing ? javascript and java are related.......... javascript in windows differs from javascript in linux....? Sorry,... if some question...
27
by: Tom Cole | last post by:
I'm starting to do more quantity of javascript coding and thought this might be a good time to investigate code styling. I primarily develop in Java and currently use the code styling techniques...
1
by: nikku0 | last post by:
hello, I wanted to know if it is possible to call a dll from javascript in linux enviornment. i know that it is possible in windows enviornment. Thanks
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.