Home Home > 2014 > 08 > 18 > Javascript tools in openSUSE round 2: js-beautify
Sign up | Login

Deprecation notice: openSUSE Lizards user blog platform is deprecated, and will remain read only for the time being. Learn more...

Javascript tools in openSUSE round 2: js-beautify

August 18th, 2014 by

I’ve been talking about how code construction is necessary to your coding project. With Javascript obfuscation or making code shine is more important than ever. There will be many many eyes looking at your code and see if it’s worth of nothing. After getting friend with js-beautify there ain’t no excuse to keep you ugly looking code laying around.

js-beautify

Js-beautify lives as (like last time JSHint tool) as a web service. If you just want to drop you Javascript code to http://jsbeautifier.org/ and see is this tools working go ahead. You can also use site to find your code guidelines parameters because you can test instantly how parameters looks like. Js-beautify github repository can be found https://github.com/beautify-web/js-beautify

How does it work?

Like last time we torture leaflet 0.7.2 minified code. It’s pain to make it look good with hand (and why one should there is good looking source available without touching minified version) with this king of example one can see how this tool really works. After installation with npm-tool or from my personal repo https://build.opensuse.org/project/show/home:illuusio:nodejs-fedora you have tool called js-beautify in you path. Running it is simple as this

js-beautify leaflet.js

after typing command one sees code outputted to STDOUT more readable form. So one can only get this like code style? No you can customize it until the bitter end of you life. If you like more K&R style formatting you can get one with:

js-beautify --brace-style=expand --indent-size=4 -f leaflet.js

Ok one have remember command line parameters every time.. nice. Actually not. There can be JSON formatted config file and defaults are like this: https://github.com/beautify-web/js-beautify/blob/master/js/config/defaults.json so using command line like this you can use your own defaults.

js-beautify --config=yourjsonconfig.json leaflet.js

Wait it’s not over yet!

With this tool there is also possibility to format CSS and HTML. You can use same js-beautify tool or short cuts css-beautify or html-beautify. These are nice tools to format HTML or CSS. There is also Python version of Js-beautify available but it’s not in focus of this post. It have same capabilities than Node.js version. So if you have read this and you code still look like dog have eat your home work then it’s your own fault. Now we have make code looking very good next time i’ll make it ugly..

Both comments and pings are currently closed.

Comments are closed.