JavaScript-Beautifier-0.17000755112327521430063 011316537470 17226 5ustar00faylandfoorumpg1502204000000000000MANIFEST000444112327521430063 25011316537470 20412 0ustar00faylandfoorumpg1502204000000000000JavaScript-Beautifier-0.17bin/js_beautify.pl Build.PL Changes lib/JavaScript/Beautifier.pm Makefile.PL MANIFEST This list of files META.yml README t/00-load.t t/01-javascript-beauty.t t/pod.t Changes000444112327521430063 323511316537470 20602 0ustar00faylandfoorumpg1502204000000000000JavaScript-Beautifier-0.17Revision history for JavaScript-Beautifier 0.17 2009.12.30 Allex Wang's fix for else { if handling js_beautify.pl [options] - (from STDIN) (RT 53220) 0.16 2009.09.22 Fixed array indentation regressions. 0.15 2009.09.17 Array tweaks 0.14 2009.08.14 Added an option for the old "function ()" syntax. Better handling of multi-dimensional arrays 0.13 2009.08.01 Pre-increment and pre-decrement fix puts spaces in front of colons in ternary expressions, e.g. a ? b : c does not put spaces in front of colons in class literals with numeric keys, e.g. { 1: "a", 2: "b" } does not put spaces between urnary +/-/! and the operand, e.g. [-a], case -1, return !a puts a new line between a new block and the start of an expression, e.g. function a() { (x || y).z() } 0.12 2009.07.26 fixed broken handline Allow unescaped / in regexp character classes. Added space between anon function parens. 0.11 2009.06.09 Fix .git MANIFEST 0.10 2009.06.08 Fix for "function" statement 0.09 2009.06.01 Strip trailing newlines, minor support for ", ""); test_beautifier( "a=/regexp", "a = /regexp" ); # incomplete regexp bt( "{a:#1=[],b:#1#,c:#999999#}", "{\n a: #1=[],\n b: #1#,\n c: #999999#\n}" ); bt("a = 1e+2"); bt("a = 1e-2"); bt( "do{x()}while(a>1)", "do {\n x()\n} while (a > 1)" ); bt( "x(); /reg/exp.match(something)", "x();\n/reg/exp.match(something)" ); bt("something();(", "something();\n("); bt("function namespace::something()"); test_beautifier( "", "" ); test_beautifier( "", ""); test_beautifier( "\n", "\n"); test_beautifier( "\n", "\n"); bt( '{foo();--bar;}', "{\n foo();\n --bar;\n}"); bt( '{foo();++bar;}', "{\n foo();\n ++bar;\n}"); bt( '{--bar;}', "{\n --bar;\n}"); bt( '{++bar;}', "{\n ++bar;\n}"); # regexps bt( 'a(/abc\\/\\/def/);b()', "a(/abc\\/\\/def/);\nb()" ); bt( 'a(/a[b\\[\\]c]d/);b()', "a(/a[b\\[\\]c]d/);\nb()" ); test_beautifier('a(/a[b\\[', "a(/a[b\\["); # incomplete char class # allow unescaped / in char classes bt( 'a(/[a/b]/);b()', "a(/[a/b]/);\nb()" ); bt( 'a=[[1,2],[4,5],[7,8]]', "a = [\n [1, 2],\n [4, 5],\n [7, 8]]" ); bt( 'a=[a[1],b[4],c[d[7]]]', "a = [a[1], b[4], c[d[7]]]" ); bt( '[1,2,[3,4,[5,6],7],8]', "[1, 2, [3, 4, [5, 6], 7], 8]" ); bt( '[[["1","2"],["3","4"]],[["5","6","7"],["8","9","0"]],[["1","2","3"],["4","5","6","7"],["8","9","0"]]]', qq~[\n [\n ["1", "2"],\n ["3", "4"]],\n [\n ["5", "6", "7"],\n ["8", "9", "0"]],\n [\n ["1", "2", "3"],\n ["4", "5", "6", "7"],\n ["8", "9", "0"]]]~ ); bt( '{[x()[0]];indent;}', "{\n [x()[0]];\n indent;\n}" ); $opts->{space_after_anon_function} = 1; bt( "// comment 1\n(function()", "// comment 1\n(function ()"); # typical greasemonkey start bt( "var a1, b1, c1, d1 = 0, c = function() {}, d = '';", "var a1, b1, c1, d1 = 0,\nc = function () {},\nd = '';"); bt( 'var o1=$.extend(a,function(){alert(x);}', "var o1 = \$.extend(a, function () {\n alert(x);\n}"); bt( 'var o1=$.extend(a);function(){alert(x);}', "var o1 = \$.extend(a);\nfunction () {\n alert(x);\n}" ); $opts->{space_after_anon_function} = 0; bt( "// comment 2\n(function()", "// comment 2\n(function()"); # typical greasemonkey start bt( "var a2, b2, c2, d2 = 0, c = function() {}, d = '';", "var a2, b2, c2, d2 = 0,\nc = function() {},\nd = '';"); bt( 'var o2=$.extend(a,function(){alert(x);}', "var o2 = \$.extend(a, function() {\n alert(x);\n}"); bt( 'var o2=$.extend(a);function(){alert(x);}', "var o2 = \$.extend(a);\nfunction() {\n alert(x);\n}"); bt( '{[y[a]];keep_indent;}', "{\n [y[a]];\n keep_indent;\n}"); bt( 'if (x) {y} else { if (x) {y}}', "if (x) {\n y\n} else {\n if (x) {\n y\n }\n}" ); $opts->{indent_size} = 1; $opts->{indent_char} = ' '; bt( '{ one_char() }', "{\n one_char()\n}" ); $opts->{indent_size} = 4; $opts->{indent_char} = ' '; bt( '{ one_char() }', "{\n one_char()\n}" ); $opts->{indent_size} = 1; $opts->{indent_char} = "\t"; # FIXME #bt( '{ one_char() }', "{\n\tone_char()\n}" ); $opts->{preserve_newlines} = 0; bt( "var\na=dont_preserve_newlines", "var a = dont_preserve_newlines" ); $opts->{preserve_newlines} = 1; bt( "var\na=do_preserve_newlines", "var\na = do_preserve_newlines" ); done_testing( $tests_num ); 1; 00-load.t000444112327521430063 26011316537470 21046 0ustar00faylandfoorumpg1502204000000000000JavaScript-Beautifier-0.17/t#!perl -T use Test::More tests => 1; BEGIN { use_ok( 'JavaScript::Beautifier' ); } diag( "Testing JavaScript::Beautifier $JavaScript::Beautifier::VERSION, Perl $], $^X" ); pod.t000444112327521430063 35011316537470 20474 0ustar00faylandfoorumpg1502204000000000000JavaScript-Beautifier-0.17/t#!perl -T use strict; use warnings; use Test::More; # Ensure a recent version of Test::Pod my $min_tp = 1.22; eval "use Test::Pod $min_tp"; plan skip_all => "Test::Pod $min_tp required for testing POD" if $@; all_pod_files_ok(); lib000755112327521430063 011316537470 17715 5ustar00faylandfoorumpg1502204000000000000JavaScript-Beautifier-0.17JavaScript000755112327521430063 011316537470 21763 5ustar00faylandfoorumpg1502204000000000000JavaScript-Beautifier-0.17/libBeautifier.pm000444112327521430063 6670611316537470 24574 0ustar00faylandfoorumpg1502204000000000000JavaScript-Beautifier-0.17/lib/JavaScriptpackage JavaScript::Beautifier; use warnings; use strict; our $VERSION = '0.17'; our $AUTHORITY = 'cpan:FAYLAND'; use base 'Exporter'; use vars qw/@EXPORT_OK/; @EXPORT_OK = qw/js_beautify/; my ( @input, @output, @modes ); my ( $token_text, $last_type, $last_text, $last_last_text, $last_word, $current_mode, $indent_string, $parser_pos, $in_case, $prefix, $token_type, $do_block_just_closed, $var_line, $var_line_tainted, $if_line_flag, $wanted_newline, $just_added_newline ); my @whitespace = split('', "\n\r\t "); my @wordchar = split('', 'abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ0123456789_$'); my @digits = split('', '0123456789'); # ') { $parser_pos += 2; if ($wanted_newline) { print_newline(); } return ['-->', 'TK_COMMENT']; } if ( grep { $c eq $_ } @punct ) { while ( $parser_pos < scalar @input && (grep { $c . $input[$parser_pos] eq $_ } @punct) ) { $c .= $input[$parser_pos]; $parser_pos++; last if ( $parser_pos >= scalar @input ); } return [$c, 'TK_OPERATOR']; } return [$c, 'TK_UNKNOWN']; } 1; __END__ =head1 NAME JavaScript::Beautifier - Beautify Javascript (beautifier for javascript) =head1 SYNOPSIS use JavaScript::Beautifier qw/js_beautify/; my $pretty_js = js_beautify( $js_source_code, { indent_size => 4, indent_character => ' ', } ); =head1 DESCRIPTION This module is mostly a Perl-rewrite of L You can check it through L =head1 FUNCTIONS =head2 js_beautify( $js_source_code, $opts ); beautify javascript. =head3 options =over 4 =item indent_size =item indent_character if you prefer Tab than Space, try: { indent_size => 1, indent_character => "\t", } =item 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 =item space_after_anon_function default is 0 =back =head1 AUTHOR Fayland Lam, C<< >> =head1 COPYRIGHT & LICENSE Copyright 2008 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. =cut