logo
Free, unlimited AI code reviews that run on commit
git-lrc git-lrc GitHub Install Now We'd appreciate a star git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt git-lrc - Free, unlimited AI code reviews that run on commit | Product Hunt

JavaScript::Beautifier - Beautify Javascript (beautifier for javascript)

Author

       Fayland Lam, "<fayland at gmail.com>"

Description

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

Functions

       $js_source_code = <<'EOF';
         a = 12;
         {return '\\w+';} EOF

   js_beautify($js_source_code,$opts);
       Beautify javascript source code contained in a string with the included options, described below.

       Options

       indent_size
       indent_character
           if you prefer Tab than Space, try:

               {
                   indent_size => 1,
                   indent_character => "\t",
               }

       preserve_newlines
           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

       space_after_anon_function
           Default is 0

Name

       JavaScript::Beautifier - Beautify Javascript (beautifier for javascript)

Synopsis

           use JavaScript::Beautifier qw/js_beautify/;

           my $pretty_js = js_beautify( $js_source_code, {
               indent_size => 4,
               indent_character => ' ',
           } );

See Also