Beautify javascript (beautifier for javascript)
use JavaScript::Beautifier qw/js_beautify/; my $pretty_js = js_beautify( $js_source_code, { indent_size => 4, indent_character => ' ', } );
This module is mostly a Perl-rewrite of <http://github.com/einars/js-beautify/tree/master/beautify.js>
You can check it through <http://jsbeautifier.org/>
beautify javascript.
options
if you prefer Tab than Space, try: { indent_size => 1, indent_character => "\t", }
default is 1 my $in = "var\na=dont_preserve_newlines"; my $out = "var a = dont_preserve_newlines"; my $js = js_beautify( $in, { preserve_newlines => 0 } ); # $out eq $js $in = "var\na=do_preserve_newlines"; $out = "var\na = do_preserve_newlines"; $js = js_beautify( $in, { preserve_newlines => 1 } ); # $out eq $js
default is 0
Fayland Lam, \*(C`<fayland at gmail.com>\*(C'
Copyright 2008 Fayland Lam, all rights reserved.
This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.