473,395 Members | 1,941 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,395 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 3361
"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...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
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...
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...
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
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
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
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 projectplanning, coding, testing,...

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.