MODULES Uize.Scruncher
SEARCHEXAMPLESVIEW SOURCE CODE

1. Introduction

The Uize.Scruncher package provides a method for scrunching (compressing / minifying) JavaScript source code into compact / obfuscated scrunched code.

DEVELOPERS: Chris van Rensburg

The Uize.Scruncher module is a package under the Uize namespace.

2. Static Methods

2.1. Uize.Scruncher.scrunch

Scrunches the specified source code string and returns an object, containing a string property for the scrunched form of the code, a string property with a report summarizing the savings from scrunching the code, and an array property containing all the comments from the source.

SYNTAX

scruncherResultOBJ = Uize.Scruncher.scrunch (sourceCodeSTR);

The returned object has the following composition...

{
  scrunchedCode:scrunchedCodeSTR, // the scrunched form of the code
  report:reportSTR,               // a multi-line summary of size savings
  comments:commentsARRAY          // an array of strings
}

The multi-line report contained in the report string property summarizes the file size savings from removed whitespace, removed comments, removed linebreaks, and scrunched identifiers. The comments array specified by the comments property can be used in the generation of comment-based documentation, as is done by the Uize.Doc.Sucker package.

VARIATION

scruncherResultOBJ = Uize.Scruncher.scrunch (sourceCodeSTR,scruncherSettingsSTR);

When the optional scruncherSettingsSTR parameter is specified, the specified Scruncher settings string will be parsed and applied to the scrunching process. This is done after the Scruncher settings have been initialized and before any of the specified source file has been parsed, so before any Scruncher settings inside the source code are encountered. Therefore, Scruncher settings inside the code being scrunched will take precedence and will override any Scruncher settings specified in the scruncherSettingsSTR parameter.

The value of the scruncherSettingsSTR parameter should have the following syntax...

[setting0Name]="[setting0Value]" [settingNName]="[settingNValue]"

This parameter is useful for providing initial values for Scruncher settings that may not be specified inside a file (or files) being scrunched, and is particularly useful when using the Scruncher in build scripts.

EXAMPLE

var scruncherResult = Uize.Scruncher.scrunch (sourceCode,'KeepHeadComment="FALSE"');

In the above example, the scruncherSettingsSTR parameter is being used to direct the Scruncher to omit the source code's head comment when scrunching it.