js-beautify 0.1.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (74) hide show
  1. data/.document +5 -0
  2. data/.gitmodules +4 -0
  3. data/Gemfile +13 -0
  4. data/Gemfile.lock +27 -0
  5. data/LICENSE.txt +20 -0
  6. data/README.rdoc +13 -0
  7. data/Rakefile +29 -0
  8. data/VERSION +1 -0
  9. data/bin/js-beautify +5 -0
  10. data/init.sh +3 -0
  11. data/js-beautify-copy/.gitmodules +3 -0
  12. data/js-beautify-copy/Makefile +71 -0
  13. data/js-beautify-copy/README.md +39 -0
  14. data/js-beautify-copy/attic/beautify-cl/beautify-cl.js +142 -0
  15. data/js-beautify-copy/attic/bin/beautify_js +80 -0
  16. data/js-beautify-copy/attic/opera-userscript/beautifier.js +1087 -0
  17. data/js-beautify-copy/attic/opera-userscript/make_opera_userscript.sh +42 -0
  18. data/js-beautify-copy/attic/qtscript/jsbeautify.cpp +121 -0
  19. data/js-beautify-copy/attic/qtscript/jsbeautify.pro +5 -0
  20. data/js-beautify-copy/attic/qtscript/jsbeautify.qrc +6 -0
  21. data/js-beautify-copy/attic/qtscript/readme.txt +28 -0
  22. data/js-beautify-copy/attic/readme.txt +2 -0
  23. data/js-beautify-copy/attic/unmaintained/bbedit/jsBeautify_BBED.scpt +522 -0
  24. data/js-beautify-copy/attic/unmaintained/c-sharp/JSBeautify.cs +801 -0
  25. data/js-beautify-copy/attic/v8/README.txt +40 -0
  26. data/js-beautify-copy/attic/v8/beautify.h +2390 -0
  27. data/js-beautify-copy/attic/v8/jsbeautify.cpp +215 -0
  28. data/js-beautify-copy/beautify-css.js +198 -0
  29. data/js-beautify-copy/beautify-html.js +514 -0
  30. data/js-beautify-copy/beautify.js +1293 -0
  31. data/js-beautify-copy/favicon.png +0 -0
  32. data/js-beautify-copy/index.html +401 -0
  33. data/js-beautify-copy/jquery/jquery.cookie.js +96 -0
  34. data/js-beautify-copy/jquery/jquery.js +167 -0
  35. data/js-beautify-copy/license.txt +24 -0
  36. data/js-beautify-copy/php/jsbeautifier.php +1599 -0
  37. data/js-beautify-copy/php/test.php +476 -0
  38. data/js-beautify-copy/python/MANIFEST.in +2 -0
  39. data/js-beautify-copy/python/js-beautify +7 -0
  40. data/js-beautify-copy/python/js-beautify-profile +16 -0
  41. data/js-beautify-copy/python/js-beautify-test +10 -0
  42. data/js-beautify-copy/python/jsbeautifier/__init__.py +1166 -0
  43. data/js-beautify-copy/python/jsbeautifier/tests/__init__.py +1 -0
  44. data/js-beautify-copy/python/jsbeautifier/tests/testindentation.py +43 -0
  45. data/js-beautify-copy/python/jsbeautifier/tests/testjsbeautifier.py +464 -0
  46. data/js-beautify-copy/python/jsbeautifier/unpackers/README.specs.mkd +25 -0
  47. data/js-beautify-copy/python/jsbeautifier/unpackers/__init__.py +67 -0
  48. data/js-beautify-copy/python/jsbeautifier/unpackers/evalbased.py +39 -0
  49. data/js-beautify-copy/python/jsbeautifier/unpackers/javascriptobfuscator.py +58 -0
  50. data/js-beautify-copy/python/jsbeautifier/unpackers/myobfuscate.py +86 -0
  51. data/js-beautify-copy/python/jsbeautifier/unpackers/packer.py +104 -0
  52. data/js-beautify-copy/python/jsbeautifier/unpackers/tests/__init__.py +2 -0
  53. data/js-beautify-copy/python/jsbeautifier/unpackers/tests/test-myobfuscate-input.js +1 -0
  54. data/js-beautify-copy/python/jsbeautifier/unpackers/tests/test-myobfuscate-output.js +65 -0
  55. data/js-beautify-copy/python/jsbeautifier/unpackers/tests/test-packer-62-input.js +1 -0
  56. data/js-beautify-copy/python/jsbeautifier/unpackers/tests/test-packer-non62-input.js +1 -0
  57. data/js-beautify-copy/python/jsbeautifier/unpackers/tests/testjavascriptobfuscator.py +46 -0
  58. data/js-beautify-copy/python/jsbeautifier/unpackers/tests/testmyobfuscate.py +40 -0
  59. data/js-beautify-copy/python/jsbeautifier/unpackers/tests/testpacker.py +34 -0
  60. data/js-beautify-copy/python/jsbeautifier/unpackers/tests/testurlencode.py +36 -0
  61. data/js-beautify-copy/python/jsbeautifier/unpackers/urlencode.py +34 -0
  62. data/js-beautify-copy/python/setup.py +17 -0
  63. data/js-beautify-copy/tests/beautify-tests.js +489 -0
  64. data/js-beautify-copy/tests/run-tests +17 -0
  65. data/js-beautify-copy/tests/sanitytest.js +128 -0
  66. data/js-beautify-copy/unpackers/javascriptobfuscator_unpacker.js +103 -0
  67. data/js-beautify-copy/unpackers/myobfuscate_unpacker.js +81 -0
  68. data/js-beautify-copy/unpackers/p_a_c_k_e_r_unpacker.js +61 -0
  69. data/js-beautify-copy/unpackers/urlencode_unpacker.js +51 -0
  70. data/lib/js-beautify.rb +0 -0
  71. data/test/helper.rb +18 -0
  72. data/test/test_js-beautify.rb +7 -0
  73. data/update.sh +23 -0
  74. metadata +173 -0
@@ -0,0 +1,5 @@
1
+ lib/**/*.rb
2
+ bin/*
3
+ -
4
+ features/**/*.feature
5
+ LICENSE.txt
@@ -0,0 +1,4 @@
1
+ [submodule "js-beautify"]
2
+ path = js-beautify
3
+ url = git@github.com:einars/js-beautify.git
4
+
data/Gemfile ADDED
@@ -0,0 +1,13 @@
1
+ source "http://rubygems.org"
2
+ # Add dependencies required to use your gem here.
3
+ # Example:
4
+ # gem "activesupport", ">= 2.3.5"
5
+
6
+ # Add dependencies to develop your gem here.
7
+ # Include everything needed to run rake, tests, features, etc.
8
+ group :development do
9
+ gem "shoulda", ">= 0"
10
+ gem "rdoc", "~> 3.12"
11
+ gem "bundler"
12
+ gem "jeweler", "~> 1.8.3"
13
+ end
@@ -0,0 +1,27 @@
1
+ GEM
2
+ remote: http://rubygems.org/
3
+ specs:
4
+ git (1.2.5)
5
+ jeweler (1.8.3)
6
+ bundler (~> 1.0)
7
+ git (>= 1.2.5)
8
+ rake
9
+ rdoc
10
+ json (1.7.3)
11
+ rake (0.9.2.2)
12
+ rdoc (3.12)
13
+ json (~> 1.4)
14
+ shoulda (3.0.1)
15
+ shoulda-context (~> 1.0.0)
16
+ shoulda-matchers (~> 1.0.0)
17
+ shoulda-context (1.0.0)
18
+ shoulda-matchers (1.0.0)
19
+
20
+ PLATFORMS
21
+ ruby
22
+
23
+ DEPENDENCIES
24
+ bundler
25
+ jeweler (~> 1.8.3)
26
+ rdoc (~> 3.12)
27
+ shoulda
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2012 hbt
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,13 @@
1
+ = js-beautify
2
+
3
+ Ruby Gem for js-beautify
4
+
5
+ == Contributing to js-beautify
6
+
7
+ * run the update.sh
8
+
9
+ == Copyright
10
+
11
+ Copyright (c) 2012 hbt. See LICENSE.txt for
12
+ further details.
13
+
@@ -0,0 +1,29 @@
1
+ # encoding: utf-8
2
+
3
+ require 'rubygems'
4
+ require 'bundler'
5
+ begin
6
+ Bundler.setup(:default, :development)
7
+ rescue Bundler::BundlerError => e
8
+ $stderr.puts e.message
9
+ $stderr.puts "Run `bundle install` to install missing gems + init submodules"
10
+ exit e.status_code
11
+ end
12
+ require 'rake'
13
+
14
+ require 'jeweler'
15
+ Jeweler::Tasks.new do |gem|
16
+ # gem is a Gem::Specification... see http://docs.rubygems.org/read/chapter/20 for more options
17
+ gem.name = "js-beautify"
18
+ gem.homepage = "http://github.com/hbt/js-beautify-gem"
19
+ gem.license = "MIT"
20
+ gem.summary = %Q{Gem for js-beautify}
21
+ gem.description = %Q{Gem for js-beautify}
22
+ gem.email = "hassenbentanfous@gmail.com"
23
+ gem.authors = ["hbt"]
24
+ gem.executables = ["js-beautify"]
25
+ # dependencies defined in Gemfile
26
+ end
27
+ Jeweler::RubygemsDotOrgTasks.new
28
+
29
+
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.1.7
@@ -0,0 +1,5 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ args = ARGV.join(' ')
4
+ script = File.join(File.absolute_path(File.dirname(__FILE__)), '../js-beautify-copy/python/js-beautify')
5
+ exec("/usr/bin/env python #{script} #{args}")
data/init.sh ADDED
@@ -0,0 +1,3 @@
1
+ #!/bin/sh
2
+
3
+ git submodule sync && git submodule init && git submodule update && git submodule foreach git fetch origin && git submodule foreach git submodule init && git submodule foreach git submodule update
@@ -0,0 +1,3 @@
1
+ [submodule "third-party/codemirror2"]
2
+ path = third-party/codemirror2
3
+ url = http://marijnhaverbeke.nl/git/codemirror2
@@ -0,0 +1,71 @@
1
+
2
+ define AVAILABLE_ACTIONS
3
+
4
+ publish: publish jsbeautifier to github.com and sync
5
+ test: test both implementations, js and python
6
+ testp: test python implementation
7
+ testj: test javascript implementation
8
+
9
+ endef
10
+ export AVAILABLE_ACTIONS
11
+
12
+
13
+ define SCRIPT_PUBLISH
14
+
15
+ open spic
16
+ cd jsbeautifier.org
17
+ mirror -Rv attic
18
+ mirror -Rv jquery
19
+ mirror -Rv tests
20
+ mirror -Rv unpackers
21
+ mirror -Rv python
22
+ put beautify-css.js beautify-html.js beautify.js index.html license.txt README.md
23
+
24
+ endef
25
+ export SCRIPT_PUBLISH
26
+
27
+
28
+ .SILENT:
29
+
30
+ all:
31
+ echo "$$AVAILABLE_ACTIONS"
32
+
33
+ publish:
34
+ git push
35
+ lftp -c "$$SCRIPT_PUBLISH"
36
+
37
+ testp:
38
+ cd python ;\
39
+ echo Testing python3 ;\
40
+ PYTHON=python3 ./js-beautify-test ;\
41
+ echo Testing python2 ;\
42
+ PYTHON=python2 ./js-beautify-test
43
+ echo
44
+
45
+ testj:
46
+ echo Testing javascript implementation...
47
+ ./tests/run-tests
48
+ echo
49
+
50
+ edit:
51
+ vim \
52
+ beautify.js python/jsbeautifier/__init__.py \
53
+ tests/beautify-tests.js python/jsbeautifier/tests/testjsbeautifier.py
54
+
55
+ gedit:
56
+ gvim \
57
+ beautify.js python/jsbeautifier/__init__.py \
58
+ tests/beautify-tests.js python/jsbeautifier/tests/testjsbeautifier.py &
59
+
60
+ tests: testj testp
61
+
62
+ test: testj testp
63
+
64
+ gh:
65
+ git push origin master &&\
66
+ cd gh-pages &&\
67
+ git pull origin master &&\
68
+ git merge master &&\
69
+ git push origin gh-pages
70
+
71
+ .PHONY: testp testj all publish edit tests test
@@ -0,0 +1,39 @@
1
+ # JS Beautifier
2
+
3
+ ...or, more specifically, all of the code powering
4
+ [jsbeautifier.org](http://jsbeautifier.org/).
5
+
6
+ This little beautifier will reformat and reindent bookmarklets, ugly
7
+ JavaScript, unpack scripts packed by Dean Edward’s popular packer,
8
+ as well as deobfuscate scripts processed by
9
+ [javascriptobfuscator.com](http://javascriptobfuscator.com/).
10
+
11
+ To beautify from the command-line you can use provided python script/library.
12
+
13
+ `./js-beautify file.js` beautifies a file, output goes to `stdout`.
14
+
15
+ To use `jsbeautifier` as a library is simple:
16
+
17
+ ``` python
18
+ import jsbeautifier
19
+ res = jsbeautifier.beautify('your javascript string')
20
+ res = jsbeautifier.beautify_file('some_file.js')
21
+ ```
22
+
23
+ ...or, to specify some options:
24
+
25
+ ``` python
26
+ opts = jsbeautifier.default_options()
27
+ opts.indent_size = 2
28
+ res = jsbeautifier.beautify('some javascript', opts)
29
+ ```
30
+
31
+ You are free to use this in any way you want, in case you find this
32
+ useful or working for you.
33
+
34
+ Written by Einar Lielmanis, <einar@jsbeautifier.org>
35
+ Python version flourished by Stefano Sanfilippo <a.little.coder@gmail.com>
36
+
37
+ Thanks to Jason Diamond, Patrick Hof, Nochum Sossonko, Andreas Schneider, Dave
38
+ Vasilevsky, Vital Batmanov, Ron Baldwin, Gabriel Harrison, Chris J. Shull,
39
+ Mathias Bynens and others.
@@ -0,0 +1,142 @@
1
+ /*
2
+
3
+ JS Beautifier Rhino command line script
4
+ ----------------------------------------
5
+
6
+ Written by Patrick Hof, <patrickhof@web.de>
7
+ "End braces on own line" added by Chris J. Shull, <chrisjshull@gmail.com>
8
+
9
+ This script is to be run with Rhino[1], the JavaScript Engine written in Java,
10
+ on the command line.
11
+
12
+ Usage:
13
+ java org.mozilla.javascript.tools.shell.Main beautify-cl.js
14
+
15
+ You are free to use this in any way you want, in case you find this useful or working for you.
16
+
17
+ [1] http://www.mozilla.org/rhino/
18
+
19
+ */
20
+
21
+ function print_usage() {
22
+ print("Usage: java org.mozilla.javascript.tools.shell.Main beautify-cl.js [options] [file || URL]\n");
23
+ print("Reads from standard input if no file or URL is specified.\n");
24
+ print("Options:");
25
+ print("-i NUM\tIndent size (1 for TAB)");
26
+ print("-b [ collapse | expand | end-expand ]\t Put braces on the same line as control statements (default), or put braces on own line (Allman / ANSI style), or just put end braces on own line");
27
+ print("-a\tIndent arrays");
28
+ print("-n\tPreserve newlines");
29
+ print("-p\tJSLint-pedantic mode, currently only adds space between \"function ()\"");
30
+ print("-d\tDirectory where the js-beautify scripts are installed.\n");
31
+ print("-h\tPrint this help\n");
32
+ print("Examples:");
33
+ print("beautify-cl.js -i 2 example.js");
34
+ print("beautify-cl.js -i 1 http://www.example.org/example.js\n");
35
+ }
36
+
37
+
38
+ function parse_opts(args) {
39
+ var options = [];
40
+ while (args.length > 0) {
41
+ param = args.shift();
42
+ if (param.substr(0, 1) == '-') {
43
+ switch (param) {
44
+ case "-i":
45
+ options.indent = args.shift();
46
+ break;
47
+ case "-b":
48
+ if (!args[0] || args[0].substr(0, 1) == '-')
49
+ options.braces_on_own_line = true;
50
+ else
51
+ options.brace_style = args.shift();
52
+ break;
53
+ case "-a":
54
+ options.keep_array_indentation = false;
55
+ break;
56
+ case "-p":
57
+ options.jslint_pedantic = true;
58
+ break;
59
+ case "-n":
60
+ options.preserve_newlines = true;
61
+ break;
62
+ case "-d":
63
+ options.install_dir = args.shift();
64
+ break;
65
+ case "-h":
66
+ print_usage();
67
+ quit();
68
+ break;
69
+ default:
70
+ print("Unknown parameter: " + param + "\n");
71
+ print("Aborting.");
72
+ quit();
73
+ }
74
+ } else {
75
+ options.source = param;
76
+ }
77
+ }
78
+ return options;
79
+ }
80
+
81
+
82
+ function do_js_beautify() {
83
+ var js_source = '';
84
+ if (options.source) { // Check if source argument is an URL
85
+ if (options.source.substring(0, 4) === 'http') {
86
+ js_source = readUrl(options.source);
87
+ } else { // Otherwise, read from file
88
+ js_source = readFile(options.source);
89
+ }
90
+ } else { // read from stdin
91
+ importPackage(java.io);
92
+ importPackage(java.lang);
93
+ var stdin = new BufferedReader(new InputStreamReader(System['in']));
94
+ var lines = [];
95
+
96
+ // read stdin buffer until EOF
97
+ while (stdin.ready()) {
98
+ lines.push(stdin.readLine());
99
+ }
100
+ if (lines.length) js_source = lines.join("\n");
101
+
102
+ if ( ! lines.length) {
103
+ print_usage();
104
+ quit();
105
+ }
106
+ }
107
+ js_source = js_source.replace(/^\s+/, '');
108
+ var indent_size = options.indent ? options.indent : 2;
109
+ var preserve_newlines = options.preserve_newlines ? options.preserve_newlines : false;
110
+ var indent_char = ' ';
111
+ var result;
112
+ if (indent_size == 1) {
113
+ indent_char = '\t';
114
+ }
115
+ if (js_source && js_source[0] === '<') {
116
+ result = style_html(js_source, indent_size, indent_char, 80);
117
+ } else {
118
+ result = js_beautify(js_source, {
119
+ indent_size: indent_size,
120
+ indent_char: indent_char,
121
+ preserve_newlines: preserve_newlines,
122
+ space_after_anon_function: options.jslint_pedantic,
123
+ keep_array_indentation: options.keep_array_indentation,
124
+ braces_on_own_line: options.braces_on_own_line,
125
+ brace_style: options.brace_style
126
+ });
127
+ }
128
+ return result;
129
+ }
130
+
131
+
132
+ options = parse_opts(arguments);
133
+
134
+ if (options.install_dir) {
135
+ load(options.install_dir + "/beautify.js");
136
+ load(options.install_dir + "/beautify-html.js");
137
+ } else {
138
+ load("beautify.js");
139
+ load("beautify-html.js");
140
+ }
141
+
142
+ print(do_js_beautify());
@@ -0,0 +1,80 @@
1
+ #!/usr/bin/ruby
2
+
3
+ def print_usage
4
+ puts <<End
5
+ Usage: #{File.basename($0)} file
6
+ Usage: echo 'JavaScript input' | #{File.basename($0)}
7
+
8
+ Using this is a vim filter command
9
+ ----------------------------------
10
+
11
+ This can also be used as a vim filter command (see help filter).
12
+
13
+ Simply select the lines to be beautified in visual mode and type .!beautify_js.
14
+
15
+ Better yet, create a vim command to execute it for you, and put that in your .vimrc:
16
+ command! -range=% -nargs=0 BeautifyJavascript <line1>,<line2>!JSBEAUTY=<q-args> #{$0}
17
+
18
+ This will allow you to invoke the command when editing a file as
19
+ :BeautifyJavascript
20
+
21
+ Additionally you can provide some of the following command line arguments:
22
+ -i <#> -- The number of spaces to indent the code;use 1 to use tabs (Def:2)
23
+ -n -- Preserve line feeds
24
+ -p -- A mode to place a space between function and () for jslint.
25
+
26
+ Examples would be:
27
+
28
+ :BeautifyJavascript -i 4 -n
29
+ :BeautifyJavascript -n
30
+
31
+ Then you can simply type BeautifyJavascript to process the entire buffer or select a range of lines to only pass those lines through the filter.
32
+ End
33
+ exit
34
+ end
35
+
36
+
37
+ if STDIN.tty?
38
+ if ARGV.size >= 1
39
+ # Get the absolute path of the filename given
40
+ require 'pathname'
41
+ last = ARGV.size - 1
42
+ args = ""
43
+ path = ""
44
+ ARGV.size.times {|i|
45
+ if i == last
46
+ path = Pathname.new(ARGV[i]).realpath.to_s
47
+ else
48
+ if i > 0
49
+ args += " "
50
+ end
51
+ args += "#{ARGV[i]}"
52
+ end
53
+ }
54
+ #path = Pathname.new(ARGV[0]).realpath.to_s
55
+ else
56
+ print_usage
57
+ end
58
+ else
59
+ # Assume they are piping the input in. Save that input in a temporary file and pass that file to beautify-cl.js
60
+ require 'tempfile'
61
+ file = Tempfile.new('beautify_js')
62
+ file.puts STDIN.read
63
+ file.close
64
+ args = ENV['JSBEAUTY'] || ""
65
+ path = file.path
66
+ end
67
+ #system "cat #{path}"
68
+
69
+
70
+ # Change directory so that the load() calls in beautify-cl.js are able to find the files they need
71
+ Dir.chdir File.dirname(File.symlink?(__FILE__) ? File.readlink(__FILE__) : __FILE__)
72
+ Dir.chdir '..'
73
+ #puts Dir.getwd
74
+
75
+
76
+ command = "rhino beautify-cl.js '#{args} #{path}' 2>&1"
77
+ #puts command
78
+ #output = `#{command}`
79
+ system command
80
+