| Conditions | 2 |
| Paths | 2 |
| Total Lines | 26 |
| Code Lines | 16 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 0 | ||
| 1 | <?php |
||
| 6 | public static function minifyJavascript($input){ |
||
| 7 | if(trim($input) === "") return $input; |
||
| 8 | $input= preg_replace( |
||
| 9 | array( |
||
| 10 | // Remove comment(s) |
||
| 11 | '#\s*("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\')\s*|\s*\/\*(?!\!|@cc_on)(?>[\s\S]*?\*\/)\s*|\s*(?<![\:\=])\/\/.*(?=[\n\r]|$)|^\s*|\s*$#', |
||
| 12 | // Remove white-space(s) outside the string and regex |
||
| 13 | '#("(?:[^"\\\]++|\\\.)*+"|\'(?:[^\'\\\\]++|\\\.)*+\'|\/\*(?>.*?\*\/)|\/(?!\/)[^\n\r]*?\/(?=[\s.,;]|[gimuy]|$))|\s*([!%&*\(\)\-=+\[\]\{\}|;:,.<>?\/])\s*#s', |
||
| 14 | // Remove the last semicolon |
||
| 15 | //'#;+\}#', |
||
| 16 | // Minify object attribute(s) except JSON attribute(s). From `{'foo':'bar'}` to `{foo:'bar'}` |
||
| 17 | '#([\{,])([\'])(\d+|[a-z_][a-z0-9_]*)\2(?=\:)#i', |
||
| 18 | // --ibid. From `foo['bar']` to `foo.bar` |
||
| 19 | '#([a-z0-9_\)\]])\[([\'"])([a-z_][a-z0-9_]*)\2\]#i' |
||
| 20 | ), |
||
| 21 | array( |
||
| 22 | '$1', |
||
| 23 | '$1$2', |
||
| 24 | //'}', |
||
| 25 | '$1$3', |
||
| 26 | '$1.$3' |
||
| 27 | ), |
||
| 28 | $input); |
||
| 29 | $input=str_replace("}$", "};$", $input); |
||
| 30 | return $input; |
||
| 31 | } |
||
| 32 | } |
||
| 34 |