---
name: "JavaScript::Beautifier"
section: "3pm"
platform: "linux"
package: "libjavascript-beautifier-perl"
version: "0.25-3"
release: "Debian 13 (Trixie)"
platforms: ["linux"]
url: "https://new.carta.tech/JavaScript::Beautifier"
---

# JavaScript::Beautifier(3pm)

Beautify Javascript (beautifier for javascript)

## 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 => ' ',
    } );
```

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

## AUTHOR

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

## COPYRIGHT & LICENSE

Copyright 2008-2018 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.
