JSMin\JSMin
JSMin.php - modified PHP implementation of Douglas Crockford's JSMin.
<code>
$minifiedJs = JSMin::minify($js);
</code>
This is a modified port of jsmin.c. Improvements:
Does not choke on some regexp literals containing quote characters. E.g. /'/
Spaces are preserved after some add/sub operators, so they are not mistakenly
converted to post-inc/dec. E.g. a + ++b -> a+ ++b
Preserves multi-line comments that begin with /*!
PHP 5 or higher is required.
Permission is hereby granted to use this version of the library under the
same terms as jsmin.c, which has the following license:
--
Copyright (c) 2002 Douglas Crockford (www.crockford.com)
Permission is hereby granted, free of charge, to any person obtaining a copy of
this software and associated documentation files (the "Software"), to deal in
the Software without restriction, including without limitation the rights to
use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies
of the Software, and to permit persons to whom the Software is furnished to do
so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all
copies or substantial portions of the Software.
The Software shall be used for Good, not Evil.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
SOFTWARE.
--
- Author: Ryan Grove <ryan@wonko.com> (PHP port)
- Copyright: 2002 Douglas Crockford <douglas@crockford.com> (jsmin.c)
- License: http://opensource.org/licenses/mit-license.php MIT License
Synopsis
- // constants
- const ORD_LF = 10;
- const ORD_SPACE = 32;
- const ACTION_KEEP_A = 1;
- const ACTION_DELETE_A = 2;
- const ACTION_DELETE_A_B = 3;
- // members
- protected string $a = "\n";
- protected string $b = '';
- protected string $input = '';
- protected integer $inputIndex = 0;
- protected integer $inputLength = 0;
- protected $lookAhead = NULL;
- protected string $output = '';
- protected string $lastByteOut = '';
- protected string $keptComment = '';
- // methods
- public static string minify()
- public void __construct()
- public string min()
- protected void action()
- protected bool isRegexpLiteral()
- protected string get()
- protected bool isEOF()
- protected string peek()
- protected bool isAlphaNum()
- protected void consumeSingleLineComment()
- protected void consumeMultipleLineComment()
- protected string next()
Constants
Name | Value |
---|---|
ORD_LF | 10 |
ORD_SPACE | 32 |
ACTION_KEEP_A | 1 |
ACTION_DELETE_A | 2 |
ACTION_DELETE_A_B | 3 |
Members
protected
- $a
- $b
- $input
- $inputIndex
- $inputLength
- $keptComment
- $lastByteOut
- $lookAhead
- $output
Methods
protected
- action() — ACTION_KEEP_A = Output A. Copy B to A. Get the next B.
- consumeMultipleLineComment() — Consume a multiple line comment from input (possibly retaining it)
- consumeSingleLineComment() — Consume a single line comment from input (possibly retaining it)
- get() — Return the next character from stdin. Watch out for lookahead. If the character is a control character, translate it to a space or linefeed.
- isAlphaNum() — Return true if the character is a letter, digit, underscore, dollar sign, or non-ASCII character.
- isEOF() — Does $a indicate end of input?
- isRegexpLiteral()
- next() — Get the next character, skipping over comments. Some comments may be preserved.
- peek() — Get next char (without getting it). If is ctrl character, translate to a space or newline.
public
- __construct()
- min() — Perform minification, return result
- minify() — Minify Javascript.