Chapter 7. Zym_Js

Chapter 7. Zym_Js

Table of Contents

7.1. Beautify
7.2. Minifier
[Note] Note

The JS family of Zym components are permanently labelled as incubatored until there is enough demand for them to move to core. If you would like to see these components move to core, drop us a line.

7.1. Beautify

This component parses obfuscated, unformatted Javascript or JSON into a human readable pretty format. The settings behind this component can be found in the API docs.

Example 7.1. Simple javascript formatting

<?php
$json = <<<JSON
{ "widget": {  "debug": "on",
   "window": {
    "title": "Sample Konfabulator Widget",
  "name": "main_window",
      "width": 500,
"height": 500
 }
 }
}
JSON;
 
$beautifier = new Zym_Js_Beautifier();
echo $beautifier->parse($json);
 
/*
{
    "widget": {
        "debug": "on",
        "window": {
            "title": "Sample Konfabulator Widget",
            "name": "main_window",
            "width": 500,
            "height": 500
        }
    }
}
*/

[Note] Note

Zym_Js_Beautify was ported from the PHP4 javascript pretty printer from http://elfz.laacz.lv/beautify/.