Packagevegas.strings
Classpublic class Minifier
InheritanceMinifier Inheritance Object
Implements Runnable

Provides a script to remove comments and unnecessary whitespaces from ECMAScript strings. You can use this class to minify .eden, .json, .js files.
     import vegas.strings.Minifier ;
     
     var input:String = "var a =       1 ; \r\n var b      = 2 ;  var c = 3    ;  " ;
     
     var minifier:JSMinifier = new JSMinifier( input , JSMinifier.NORMAL ) ;
     
     minifier.run() ;
     
     var output:String = minifier.output ; 
     
     trace("old size : " + minifier.oldSize ) ;
     trace("new size : " + minifier.newSize ) ;
     trace("input    : " + minifier.input ) ;
     trace("output   : " + output ) ;
     



Public Properties
 PropertyDefined By
  input : String
The input String to minimize.
Minifier
  level : uint
The level of compression of the minifier.
Minifier
  newSize : uint
[read-only] Indicates the new size of the output source.
Minifier
  oldSize : uint
[read-only] Indicates the original size of the input source.
Minifier
  output : String
[read-only] The output result of the minifier process.
Minifier
Public Methods
 MethodDefined By
  
Minifier(input:String, level:uint = 2)
Creates a new JSMinifier instance.
Minifier
  
run(... arguments):void
minify the javascript/ecmascript String input value.
Minifier
Protected Methods
 MethodDefined By
  
action(d:uint):String
Do something! What you do is determined by the argument: 1 : Output A.
Minifier
Public Constants
 ConstantDefined By
  AGRESSIVE : uint = 3
[static] Remove more linefeed than the original algorithm but can be regressive
Minifier
  MINIMAL : uint = 1
[static] Original algorithm but keep linefeeds if single.
Minifier
  NORMAL : uint = 2
[static] Original algorithm (conservative).
Minifier
Property Detail
inputproperty
input:String

The input String to minimize.


Implementation
    public function get input():String
    public function set input(value:String):void
levelproperty 
level:uint

The level of compression of the minifier.


Implementation
    public function get level():uint
    public function set level(value:uint):void
newSizeproperty 
newSize:uint  [read-only]

Indicates the new size of the output source.


Implementation
    public function get newSize():uint
oldSizeproperty 
oldSize:uint  [read-only]

Indicates the original size of the input source.


Implementation
    public function get oldSize():uint
outputproperty 
output:String  [read-only]

The output result of the minifier process.


Implementation
    public function get output():String
Constructor Detail
Minifier()Constructor
public function Minifier(input:String, level:uint = 2)

Creates a new JSMinifier instance.

Parameters
input:String — The String source to minify.
 
level:uint (default = 2) — The level of compression :
  • 1 : minimal, keep linefeeds if single
  • 2 : normal, the standard algorithm
  • 3 : agressive, remove any linefeed and doesn't take care of potential missing semicolons (can be regressive)
  • Method Detail
    action()method
    protected function action(d:uint):String

    Do something! What you do is determined by the argument: 1 : Output A. Copy B to A. Get the next B. 2 : Copy B to A. Get the next B. (Delete A). 3 : Get the next B. (Delete B). action treats a string as a single character. Wow! action recognizes a regular expression if it is preceded by ( or , or =.

    Parameters

    d:uint

    Returns
    String
    run()method 
    public function run(... arguments):void

    minify the javascript/ecmascript String input value.

    Parameters

    ... arguments

    Constant Detail
    AGRESSIVEConstant
    public static const AGRESSIVE:uint = 3

    Remove more linefeed than the original algorithm but can be regressive

    MINIMALConstant 
    public static const MINIMAL:uint = 1

    Original algorithm but keep linefeeds if single.

    NORMALConstant 
    public static const NORMAL:uint = 2

    Original algorithm (conservative).