PHP code example of matheusab / php-js-pretty-printer

1. Go to this page and download the library: Download matheusab/php-js-pretty-printer library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

matheusab / php-js-pretty-printer example snippets


use MAB\JS\JS;

$js = JS::object([
    'string'  => 'myStringValue',
    'rawJS'   => JS::raw("() => {}"),
    'array1'  => [1, 2, 3],
    'array2'  => JS::array(1, 2, 3), // same as array1
    'array3'  => JS::array(1, 2, 3)->breakLine(),
    'object1' => [
        'a' => 1,
        'b' => 2
    ],
    'object2' => JS::object([ //same as object1
        'a' => 1,
        'b' => 2
    ]),
]);

echo $js;



use MAB\JS\JS;

echo JS::object($map)->format();
echo JS::array(...$values)->format();
echo JS::format($lines);


$object = JS::object();
$object['a'] = 1;

// equivalent to

$object = JS::object(['a' => 1]); 

$array = JS::array(1);

// equivalent to

$array = JS::array();
$array[] = 1;

echo JS::object();

// is equivalent to

echo JS::object()->format();

echo JS::object([
    'a' => [
        'a_a' => 1,
        'a_b' => 2,
    ],
    'b' => JS::object([
        'b_a' => 1,
        'b_b' => 2
    ])
]);