JavaSc...tifier(3pm)

πŸ“¦
version 0.25 Β· 4 versions
, in debian bookworm, debian trixie, ubuntu noble, ubuntu resolute, ubuntu stonking

πŸ’– JavaScript::Beautifier β€” the manual, but make it cute πŸ’–

okay so bestie, gather round, because this is JavaScript::Beautifier (perl module, manual section 3pm, lives in User Contributed Perl Documentation) and it does exactly one iconic thing: it makes your cursed, unreadable JavaScript look pretty. ✨


🌸 NAME 🌸

JavaScript::Beautifier β€” Beautify Javascript (beautifier for javascript). yes, it's a beautifier. for javascript. we said it twice because it's THAT serious. πŸ’…


πŸŽ€ SYNOPSIS πŸŽ€

use JavaScript::Beautifier qw/js_beautify/;

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

look at that. one import, one function call, and your JS stops looking like it fell down the stairs. no cap. πŸ¦‹


✨ DESCRIPTION ✨

This module is mostly a Perl-rewrite of http://github.com/einars/js-beautify/tree/master/beautify.js β€” so if you know that one, you already know the vibe. iykyk. 🧚

You can check it through http://jsbeautifier.org/ if you wanna see it in action before committing. 🫢


πŸ”₯ FUNCTIONS πŸ”₯

First, here's the lil string we're gonna be working with in the examples β€” look at how messy it is, honestly, a crime scene:

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

πŸ‘‘ js_beautify( $js_source_code, $opts );

Beautify javascript source code contained in a string, using the options you pass in (they're all described right below, keep scrolling bestie ⬇️).

πŸ’… Options

  • indent_size β€” how big your indent is. that's it, that's the option.
  • indent_character β€” what character does the indenting. and if you're a Tab person instead of a Space person (we don't judge... okay we judge a little πŸ™ˆ), try this:
{
    indent_size => 1,
    indent_character => "\t",
}
  • preserve_newlines β€” default is 1. watch it do its thing in both directions:
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

so like, with 0 your newlines get smooshed into one line, with 1 they stay put. slay. 🌈

  • space_after_anon_function β€” default is 0. (that's literally all the docs say about it, so that's all we're saying about it, don't come for me 😭)

🫢 AUTHOR 🫢

Fayland Lam, "<fayland at gmail.com>" β€” the icon who wrote this. bow down. πŸ‘‘


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.

fr fr, same terms as Perl itself β€” go read those, we're not retyping them here.

and that's the whole page bestie, we ate and left no crumbs πŸ’…βœ¨

cute lil sign-off: this was perl v5.36.0, dated 2022-11-29, and yes the page header/footer kept getting abbreviated to JavaSc...tifier(3pm) because even the man page formatter couldn't handle the full name's main character energy. πŸ’€πŸŽ€ bye!!

πŸ“¦ where this page comes from