Skip to content

Instantly share code, notes, and snippets.

@fcamel
Created July 24, 2011 14:52
Show Gist options
  • Save fcamel/1102696 to your computer and use it in GitHub Desktop.
Save fcamel/1102696 to your computer and use it in GitHub Desktop.
indent js
#!/usr/bin/perl
use strict;
use warnings;
use JavaScript::Beautifier qw/js_beautify/;
if ($#ARGV != 1) {
print "jsindent <in file> <out file>\n";
exit(1);
}
open(FR, $ARGV[0]) or die "can't open $ARGV[0]: $!";
my @lines = <FR>;
close(FR);
my $js_source_code = join("\n", @lines);
my $pretty_js = js_beautify( $js_source_code, {
indent_size => 4,
indent_character => ' ',
} );
open(FW, ">$ARGV[1]") or die "can't write to $ARGV[1]: $!";
print FW $pretty_js;
close(FW);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment