``` ██████╗ ██████╗ ██╗ ██╗███████╗██████╗ ██╔══██╗██╔═══██╗██║ ██║██╔════╝██╔══██╗ ██████╔╝██║ ██║██║ █╗ ██║█████╗ ██████╔╝ ██╔═══╝ ██║ ██║██║███╗██║██╔══╝ ██╔══██╗ ██║ ╚██████╔╝╚███╔███╔╝███████╗██║ ██║ ╚═╝ ╚═════╝ ╚══╝╚══╝ ╚══════╝╚═╝ ╚═╝ ``` # class JavaScript (Details) > namespace: **VDM\Minify** ```uml @startuml class JavaScript #Gold { # $keywordsReserved # $keywordsBefore # $keywordsAfter # $operatorsBefore + execute(string[optional] $path = null) : string # stripComments() # extractRegex() # stripWhitespace(string $content) : string # getOperatorsForRegex(array $operators, string $delimiter = '/') : string[] # getKeywordsForRegex(array $keywords, string $delimiter = '/') : string[] # propertyNotation(string $content) : string # shortenBools(string $content) : string } note right of JavaScript::execute Minify the data. Perform JS optimizations. return: string end note note left of JavaScript::stripComments Strip comments from source code. end note note right of JavaScript::extractRegex JS can have /-delimited regular expressions, like: /ab+c/.match(string). The content inside the regex can contain characters that may be confused for JS code: e.g. it could contain whitespace it needs to match & we don't want to strip whitespace in there. The regex can be pretty simple: we don't have to care about comments, (which also use slashes) because stripComments() will have stripped those already. This method will replace all string content with simple REGEX# placeholder text, so we've rid all regular expressions from characters that may be misinterpreted. Original regex content will be saved in $this->extracted and after doing all other minifying, we can restore the original content via restoreRegex() end note note left of JavaScript::stripWhitespace Strip whitespace. We won't strip *all* whitespace, but as much as possible. The thing that we'll preserve are newlines we're unsure about. JavaScript doesn't require statements to be terminated with a semicolon. It will automatically fix missing semicolons with ASI (automatic semi- colon insertion) at the end of line causing errors (without semicolon.) Because it's sometimes hard to tell if a newline is part of a statement that should be terminated or not, we'll just leave some of them alone. return: string end note note right of JavaScript::getOperatorsForRegex We'll strip whitespace around certain operators with regular expressions. This will prepare the given array by escaping all characters. return: string[] end note note left of JavaScript::getKeywordsForRegex We'll strip whitespace around certain keywords with regular expressions. This will prepare the given array by escaping all characters. return: string[] end note note right of JavaScript::propertyNotation Replaces all occurrences of array['key'] by array.key. return: string end note note left of JavaScript::shortenBools Replaces true & false by !0 and !1. return: string end note @enduml ``` --- ``` ██╗ ██████╗██████╗ ██║██╔════╝██╔══██╗ ██║██║ ██████╔╝ ██ ██║██║ ██╔══██╗ ╚█████╔╝╚██████╗██████╔╝ ╚════╝ ╚═════╝╚═════╝ ``` > Build with [Joomla Component Builder](https://git.vdm.dev/joomla/Component-Builder)