471,596 Members | 810 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

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

Javascript formatter tool

I there any good javascript formatter tool? (format javascript
accurately, etc)

Mistral

Jun 9 '06 #1
3 3318
"mistral" <po*******@softhome.net> writes:
I there any good javascript formatter tool? (format javascript
accurately, etc)


Most non-IE browsers can do it for you. Try the following in Firefox
or Opera:
---
function formatJS(jsText) {
var funcString = new Function(jsText).toString();
var match =
/^\s*function\s*\w*\s*\(\s*\)\s*\{([\s\S]*)\}\s*$/.exec(funcString);
if (match) {
return match[1];
} else {
// unable to parse function expression
}
}
---

It's not perfect (it removes comments), but it doesn't get much simpler :)

/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.'
Jun 9 '06 #2

Lasse Reichstein Nielsen писал(а):
"mistral" <po*******@softhome.net> writes: I there any good javascript formatter tool? (format javascript accurately, etc)

-----------------------------------------------------------------------------------------------

Most non-IE browsers can do it for you. Try the following in Firefox or
Opera:

function formatJS(jsText) {
var funcString = new Function(jsText).toString();
var match =

/^\s*function\s*\w*\s*\(\s*\)\s*\{([\s\S]*)\}\s*$/.exec(funcString);
if (match) {
return match[1];
} else {
// unable to parse function expression
}
}

It's not perfect (it removes comments), but it doesn't get much
simpler :)

/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.'
=======================================

Well, but I use Internet Explorer only.

Mistral

Jun 12 '06 #3
"mistral" <po*******@softhome.net> writes:
Well, but I use Internet Explorer only.


I guess it's as good a time as any to change that :)
You can have more than one browser installed at the same time,
so you can install Firefox and use it just for this, and still use
IE for your browsing needs.

/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.'
Jun 12 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

4 posts views Thread by Inge | last post: by
8 posts views Thread by John Dalberg | last post: by
17 posts views Thread by Jeff Robichaud | last post: by
reply views Thread by Kalle Anke | last post: by
4 posts views Thread by Patrick De Ridder | last post: by
4 posts views Thread by Carlitos | last post: by
8 posts views Thread by Surendra Singhi | last post: by
6 posts views Thread by Melih Onvural | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by leo001 | last post: by
reply views Thread by Anwar ali | last post: by

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.