JSMin
in package
jsmin.php - PHP implementation of Douglas Crockford's JSMin.
This is a direct port of jsmin.c to PHP with a few PHP performance tweaks and modifications to preserve some comments (see below). Also, rather than using stdin/stdout, JSMin::minify() accepts a string as input and returns another string as output.
Comments containing IE conditional compilation are preserved, as are multi-line comments that begin with "/*!" (for documentation purposes). In the latter case newlines are inserted around the comment to enhance readability.
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.
Tags
Table of Contents
Constants
- ACTION_DELETE_A = 2
- ACTION_DELETE_A_B = 3
- ACTION_KEEP_A = 1
- ORD_LF = 10
- ORD_SPACE = 32
Properties
- $a : mixed
- $b : mixed
- $input : mixed
- $inputIndex : mixed
- $inputLength : mixed
- $lookAhead : mixed
- $output : mixed
Methods
- __construct() : mixed
- Setup process
- min() : mixed
- Perform minification, return result
- minify() : string
- Minify Javascript
- action() : mixed
- ACTION_KEEP_A = Output A. Copy B to A. Get the next B.
- get() : mixed
- Get next char. Convert ctrl char to space.
- isAlphaNum() : mixed
- Is $c a letter, digit, underscore, dollar sign, escape, or non-ASCII?
- isRegexpLiteral() : mixed
- multipleLineComment() : mixed
- next() : mixed
- Get the next character, skipping over comments.
- peek() : mixed
- Get next char. If is ctrl character, translate to a space or newline.
- singleLineComment() : mixed
Constants
ACTION_DELETE_A
public
mixed
ACTION_DELETE_A
= 2
ACTION_DELETE_A_B
public
mixed
ACTION_DELETE_A_B
= 3
ACTION_KEEP_A
public
mixed
ACTION_KEEP_A
= 1
ORD_LF
public
mixed
ORD_LF
= 10
ORD_SPACE
public
mixed
ORD_SPACE
= 32
Properties
$a
protected
mixed
$a
= "\n"
$b
protected
mixed
$b
= ''
$input
protected
mixed
$input
= ''
$inputIndex
protected
mixed
$inputIndex
= 0
$inputLength
protected
mixed
$inputLength
= 0
$lookAhead
protected
mixed
$lookAhead
= \null
$output
protected
mixed
$output
= ''
Methods
__construct()
Setup process
public
__construct(mixed $input) : mixed
Parameters
- $input : mixed
min()
Perform minification, return result
public
min() : mixed
minify()
Minify Javascript
public
static minify(string $js) : string
Parameters
- $js : string
-
Javascript to be minified
Return values
stringaction()
ACTION_KEEP_A = Output A. Copy B to A. Get the next B.
protected
action(mixed $command) : mixed
ACTION_DELETE_A = Copy B to A. Get the next B. ACTION_DELETE_A_B = Get the next B.
Parameters
- $command : mixed
get()
Get next char. Convert ctrl char to space.
protected
get() : mixed
isAlphaNum()
Is $c a letter, digit, underscore, dollar sign, escape, or non-ASCII?
protected
isAlphaNum(mixed $c) : mixed
Parameters
- $c : mixed
isRegexpLiteral()
protected
isRegexpLiteral() : mixed
multipleLineComment()
protected
multipleLineComment() : mixed
next()
Get the next character, skipping over comments.
protected
next() : mixed
Some comments may be preserved.
peek()
Get next char. If is ctrl character, translate to a space or newline.
protected
peek() : mixed
singleLineComment()
protected
singleLineComment() : mixed