Debian Codegraph @

README.md

raw symbols SCIP
1 # rJSmin - A Javascript Minifier For Python
2
3 TABLE OF CONTENTS
4 -----------------
5
6 1. Introduction
7 1. Copyright and License
8 1. System Requirements
9 1. Installation
10 1. Documentation
11 1. Bugs
12 1. Author Information
13
14
15 ## INTRODUCTION
16
17 rJSmin is a javascript minifier written in python.
18
19 The minifier is based on the semantics of [jsmin.c by Douglas
20 Crockford](http://www.crockford.com/javascript/jsmin.c).
21
22 The module is a re-implementation aiming for speed, so it can be used at
23 runtime (rather than during a preprocessing step). Usually it produces the
24 same results as the original ``jsmin.c``. It differs in the following ways:
25
26 - there is no error detection: unterminated string, regex and comment
27 literals are treated as regular javascript code and minified as such.
28 - Control characters inside string and regex literals are left untouched; they
29 are not converted to spaces (nor to \\n)
30 - Newline characters are not allowed inside string and regex literals, except
31 for line continuations in string literals (ECMA-5).
32 - "return /regex/" is recognized correctly.
33 - More characters are allowed before regexes.
34 - Line terminators after regex literals are handled more sensibly
35 - "+ +" and "- -" sequences are not collapsed to '++' or '--'
36 - Newlines before ! operators are removed more sensibly
37 - (Unnested) template literals are supported (ECMA-6)
38 - Comments starting with an exclamation mark (``!``) can be kept optionally
39 - rJSmin does not handle streams, but only complete strings. (However, the
40 module provides a "streamy" interface).
41
42 Since most parts of the logic are handled by the regex engine it's way faster
43 than the original python port of ``jsmin.c`` by Baruch Even. The speed factor
44 varies between about 6 and 55 depending on input and python version (it gets
45 faster the more compressed the input already is). Compared to the
46 speed-refactored python port by Dave St.Germain the performance gain is less
47 dramatic but still between 3 and 50 (for huge inputs). See the docs/BENCHMARKS
48 file for details.
49
50 rjsmin.c is a reimplementation of rjsmin.py in C and speeds it up even more.
51
52 * [Change Log](CHANGES)
53 * [Development](docs/DEVELOPMENT.md)
54
55
56 ## COPYRIGHT AND LICENSE
57
58 Copyright 2011 - 2025
59 André Malo or his licensors, as applicable.
60
61 The whole package (except for the files in the bench/ directory)
62 is distributed under the Apache License Version 2.0. You'll find a copy in the
63 root directory of the distribution or online at:
64 <http://www.apache.org/licenses/LICENSE-2.0>.
65
66
67 ## SYSTEM REQUIREMENTS
68
69 Supported python versions are 2.7 and 3.6+.
70
71 You also need a build environment for python C extensions (i.e. a compiler
72 and the python development files).
73
74
75 ## INSTALLATION
76
77 ### Using pip
78
79 ```
80 $ pip install rjsmin
81 ```
82
83
84 ### Using distutils
85
86 Download the package, unpack it, change into the directory
87
88 ```
89 $ python setup.py install
90 ```
91
92 The command above will install a new "rjsmin" package into python's
93 library path.
94
95
96 ### Drop-in
97
98 rJSmin effectively consists of two files: rjsmin.py and rjsmin.c, the
99 latter being entirely optional. So, for simple integration you can just
100 copy rjsmin.py into your project and use it.
101
102
103 ## DOCUMENTATION
104
105 The module provides a simple function, called jsmin which takes the script as
106 a string and returns the minified script as a string.
107
108 The module additionally provides a "streamy" interface similar to the one
109 jsmin.c provides:
110
111 ```
112 $ python -mrjsmin <script >minified
113 ```
114
115 It takes two options:
116
117 -b Keep bang-comments (Comments starting with an exclamation mark)
118 -p Force using the python implementation (not the C implementation)
119
120 The latest documentation is also available online at
121 <http://opensource.perlig.de/rjsmin/>.
122
123
124 ## BUGS
125
126 No bugs, of course. ;-)
127 But if you've found one or have an idea how to improve rjsmin, feel free
128 to send a pull request on [github](https://github.com/ndparker/rjsmin)
129 or send a mail to <[email protected]>.
130
131
132 ## AUTHOR INFORMATION
133
134 AndrĂ© "nd" Malo <[email protected]>, GPG: 0x029C942244325167
135
136
137 > If God intended people to be naked, they would be born that way.
138 > -- Oscar Wilde