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
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.