0.2.9 • Published 6 years ago

php-unparser v0.2.9

Weekly downloads
45
License
MIT
Repository
github
Last release
6 years ago

php-unparser

Build Status Coverage Status

This project is a JavaScript based unparser for the AST produced by glayzzle's php-parser.

It aims to produce code that uses the style format recommended by PSR-1 and PSR-2.

It's at an early development stage, but it is already able to generate code for most of the produced AST.

It has no dependencies.

How to use

var unparse = require('php-unparser');

var options = {
  indent: true,
  dontUseWhitespaces: false,
  shortArray: true,
  bracketsNewLine: true,
  forceNamespaceBrackets: false,
  collapseEmptyLines: true
};

var ast = {
  "kind": "program",
  "children": [
    {
      "kind": "echo",
      "arguments": [
        {
          "kind": "string",
          "value": "hello world",
          "isDoubleQuote": true
        }
      ]
    }
  ],
  "errors": []
};

// Will output -> echo "hello world";
console.log(unparse(ast, options));

Options

optionvaluedefaultdescription
indentstringThe indentation size, default is four white spaces.
dontUseWhitespacesbooleanfalseIf enabled removes all the whitespaces between stuff.
shortArraybooleanfalseIf enabled write arrays in short array syntax enabled since PHP 5.4.0
bracketsNewLinebooleantrueIf enabled will put brackets on new line.
forceNamespaceBracketsbooleanfalseForce the namespace bracketed syntax (recommended for combining namespaces)
collapseEmptyLinesbooleantrueIf enabled it will remove all empty lines between sections and properties.

Demo

See it working

License

MIT License, Copyright 2016 Christopher Luna

0.2.9

6 years ago

0.2.8

6 years ago

0.2.7

6 years ago

0.2.6

6 years ago

0.2.5

6 years ago

0.2.4

6 years ago

0.2.3

7 years ago

0.2.2

7 years ago

0.2.1

7 years ago

0.2.0

7 years ago

0.1.4

7 years ago

0.1.3

7 years ago

0.1.2

7 years ago

0.1.1

7 years ago

0.1.0

7 years ago