"rlScriptShrink.js" (rlBoot.bootRefugeeLib does not load this script by default)
Experimental tokenization based script shrinking/expanding.
Limitation: string constants containing a "@:" prefixed by one or
more of the modified base64 symbols may lead to those being recursively replaced when a shrunk
script is being expanded again.
- To Do:
-
- add method to load, shrink and save in one step / loadFromURL(s), loadFromFile(s)
Members
-
(private, static, constant) b
-
modified base64 symbols using chars `# instead of +/ (which are valid js operators) which are used in placeholder/token ids
- Default Value:
- ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789`#
Methods
-
(static) getExpansion(s, p, c) → {string}
-
Replace token identifiers in a source string with token contents.
Parameters:
Name Type Description sstring a string containing prefixed(@id) and/or suffixed(id@:) token identifiers (id is a number encoded in modified base64 symbols)
pArray.<string> an array containing the token contents for the token identifiers (index is the token id)
cnumber set negative to replace prefixed, zero or positive to replace suffixed token identifiers in s with the token contents
Returns:
the modified source string where the token identifiers have been replaced with the token contents
- Type
- string
-
(static) getPreparedData(shrinkData) → {Array.<string>}
-
Get prepared data from the given shrink data.
Parameters:
Name Type Description shrinkDatarlScriptShrink.shrinkData previously generated shrink data
Returns:
an array of strings ready to be passed to
rlScriptShrink.getSelfExpandingScript- Type
- Array.<string>
-
(static) getSelfExpandingScript(preparedData) → {string}
-
Get a string whose content can be saved to a .js file which expands itself when it is included in a <script> tag.
Parameters:
Name Type Description preparedDataArray.<string> must be the data returned from
rlScriptShrink.getPreparedDataReturns:
- Type
- string
-
(static) getShrinkData(s) → {rlScriptShrink.shrinkData}
-
Get shrink data for the given script content.
Parameters:
Name Type Description sstring a string containing the script content to shrink
Returns:
shrinkData ready to be passed to
rlScriptShrink.getPreparedData
Type Definitions
-
shrinkData
-
(not an actual type, use object literals with these properties)
Properties:
Name Type Description stringTokensArray.<string> contains all found string tokens from a script
codeTokensArray.<string> contains all found code tokens from a script which were worth replacing to save on character count
tokenizedInputstring a shrunk version of a script where unnecessary whitespace and all comments haven been stripped and string and code tokens have been replaced with placeholders (the placeholder ids are encoded numbers in modified base64 symbols, the ids refer to indices within the stringTokens and codeTokens arrays)
inputCharCountnumber the number of characters in the source script
tokenizedCharCountnumber the number of character in the tokenized shrunk version of the script