\JSMin

JSMin.php - modified PHP implementation of Douglas Crockford's JSMin.

$minifiedJs = JSMin::minify($js);

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.

Summary

Methods
Properties
Constants
minify()
__construct()
min()
No public properties found
ORD_LF
ORD_SPACE
ACTION_KEEP_A
ACTION_DELETE_A
ACTION_DELETE_A_B
action()
isRegexpLiteral()
get()
isEOF()
peek()
isAlphaNum()
consumeSingleLineComment()
consumeMultipleLineComment()
next()
$a
$b
$input
$inputIndex
$inputLength
$lookAhead
$output
$lastByteOut
$keptComment
N/A
No private methods found
No private properties found
N/A

Constants

ORD_LF

ORD_LF

ORD_SPACE

ORD_SPACE

ACTION_KEEP_A

ACTION_KEEP_A

ACTION_DELETE_A

ACTION_DELETE_A

ACTION_DELETE_A_B

ACTION_DELETE_A_B

Properties

$a

$a : 

Type

$b

$b : 

Type

$input

$input : 

Type

$inputIndex

$inputIndex : 

Type

$inputLength

$inputLength : 

Type

$lookAhead

$lookAhead : 

Type

$output

$output : 

Type

$lastByteOut

$lastByteOut : 

Type

$keptComment

$keptComment : 

Type

Methods

minify()

minify(string  $js) : string

Minify Javascript.

Parameters

string $js

Javascript to be minified

Returns

string

__construct()

__construct(string  $input) 

Parameters

string $input

min()

min() : string

Perform minification, return result

Returns

string

action()

action(integer  $command) 

ACTION_KEEP_A = Output A. Copy B to A. Get the next B.

ACTION_DELETE_A = Copy B to A. Get the next B. ACTION_DELETE_A_B = Get the next B.

Parameters

integer $command

Throws

\JSMin_UnterminatedRegExpException|\JSMin_UnterminatedStringException

isRegexpLiteral()

isRegexpLiteral() : boolean

Returns

boolean

get()

get() : string

Return the next character from stdin. Watch out for lookahead. If the character is a control character, translate it to a space or linefeed.

Returns

string

isEOF()

isEOF(string  $a) : boolean

Does $a indicate end of input?

Parameters

string $a

Returns

boolean

peek()

peek() : string

Get next char (without getting it). If is ctrl character, translate to a space or newline.

Returns

string

isAlphaNum()

isAlphaNum(string  $c) : boolean

Return true if the character is a letter, digit, underscore, dollar sign, or non-ASCII character.

Parameters

string $c

Returns

boolean

consumeSingleLineComment()

consumeSingleLineComment() 

Consume a single line comment from input (possibly retaining it)

consumeMultipleLineComment()

consumeMultipleLineComment() 

Consume a multiple line comment from input (possibly retaining it)

Throws

\JSMin_UnterminatedCommentException

next()

next() : string

Get the next character, skipping over comments. Some comments may be preserved.

Returns

string