473,799 Members | 3,267 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Javascript formatter tool

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

Mistral

Jun 9 '06 #1
3 3373
"mistral" <po*******@soft home.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(funcStrin g);
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/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jun 9 '06 #2

Lasse Reichstein Nielsen писал(а):
"mistral" <po*******@soft home.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(funcStrin g);
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/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
=============== =============== =========

Well, but I use Internet Explorer only.

Mistral

Jun 12 '06 #3
"mistral" <po*******@soft home.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/rasterTriangleD OM.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
3120
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 complex, to a file, console window or the output window in visual studio. niceSQL is an sql formatter. niceSQL formattes your sql statements so that they become well arranged. It
8
1958
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 a .NET tool at codeproject but that site is down.
17
1840
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 mistakes that I make when coding in javascript are syntax-related. Here's a typical scenario: I use a function like getElementByID. Notice the big D...In Internet Explorer I get the classic "object doesn't support this property or method" message,...
0
2023
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 managed to find one but have probably been looking in the wrong places.
4
5980
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
2183
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 TheDataManager(); File MyDataFile = new File(strDataPath); // Create a new file if and only if it doesn't already exist
8
5466
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 prosperity of Crime is like unto the lightning,
6
3579
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 myparser(htmllib.HTMLParser): insave = 0 def start_div(self, attrs): for i in attrs: if i == "id" and i == "pr":
0
9688
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, well explore What is ONU, What Is Router, ONU & Routers main usage, and What is the difference between ONU and Router. Lets take a closer look ! Part I. Meaning of...
0
9546
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 effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10260
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 tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10030
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9078
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, and deploymentwithout human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
0
6809
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5467
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5590
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
3
2941
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.