473,385 Members | 1,320 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,385 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 3360
"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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

4
by: Inge | last post by:
Hi! I have developed an usefor tool for developers. Take a look. niceSQL is a nice-to-have tool for developers. the application you develop logs the sql statements, that often are big and very...
8
by: John Dalberg | last post by:
I have spent 1/2 hour looking for a Javascript formatter with no luck. I am using a tool that produces Javascript statements in one long string and it's hard to read. Any recommendations? I see...
17
by: Jeff Robichaud | last post by:
Hi, I would like to know if there exists a tool that one can use to test some javascript code before actually running it ? Something that would check the syntax at least ? I found that most...
0
by: Kalle Anke | last post by:
Does a Java "pretty formatter" exist? I would like to use a Python based web building tool but would like to pretty format Java code (for example adding color to keywords, etc). I haven't...
4
by: Patrick De Ridder | last post by:
Which library should I include for the formatter in formatter.Serialize(output, record); Many thanks. -- Patrick De Ridder ngmail@freeler.nl
4
by: Carlitos | last post by:
I have researched a lot trying to get this. So as a last resource I will have to ask here. What would be the equivalent to the following javascript excerpt: TheDataManager MyDMgr = new...
8
by: Surendra Singhi | last post by:
Hello, Are there any good open source C/C++ source code formatter? Thanks for your help. -- Surendra Singhi http://www.public.asu.edu/~sksinghi/index.html ,---- | "O thou my friend! The...
6
by: Melih Onvural | last post by:
I need to execute some javascript and then read the value as part of a program that I am writing. I am currently doing something like this: import htmllib, urllib, formatter class...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...

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.