JavaSc...tifier(3pm)
π 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 is1. 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 is0. (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 & 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.
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
- debian bookworm: libjavascript-beautifier-perl 0.25-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- debian trixie: libjavascript-beautifier-perl 0.25-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu noble: libjavascript-beautifier-perl 0.25-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu resolute: libjavascript-beautifier-perl 0.25-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- ubuntu stonking: libjavascript-beautifier-perl 0.25-3 Β· Artistic-1.0-Perl OR GPL-1.0-or-later
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms