JavaScript::Beautifier(3pm)

JavaScript::Beautifier3pm

Beautify javascript (beautifier for javascript)

Usage

    use JavaScript::Beautifier qw/js_beautify/;
    my $pretty_js = js_beautify( $js_source_code, {
        indent_size => 4,
        indent_character => ' ',
    } );

Overview

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

Releases

8 releases since Debian 6.0 (Squeeze); the text changed 4 times.

  1. 6.0–8
  2. 9
  3. 10
  4. 11
  5. 12–13

Author

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

From libjavascript-beautifier-perl 0.25-3 in Debian 13 (Trixie). Parsed by carta from the page's man source.