• Stars
    star
    9
  • Rank 1,882,947 (Top 39 %)
  • Language
    TypeScript
  • Created over 5 years ago
  • Updated over 5 years ago

Reviews

There are no reviews yet. Be the first to send feedback to the community and the maintainers!

Repository Details

An NGINX config parser and AST generator

NGINX Config AST

A parser and code generator for NGINX configuration files

Usage:

var parser = require('nginx-config-ast');

var config = `
    server {
        listen 80;

        server_name example.com;
        location / {
            root /etc/nginx/html;
            try_files $uri $uri/ $uri.html =404;
        }
    }
`;

// You can convert the configuration into an abstract tree (AST)
var ast = parser.generateAST(config);

// You can also convert the AST back to a configuration
var code = parser.generateConfig(ast);

Methods

isConfigValid (config)

Checks if the configuration is valid and returns a boolean.

Arguments

  • config: string - Code of a NGINX configuration file

generateAST (config, options)

Generates and returns an abstract tree for specified configuration code.

Arguments

  • config: string - Code of a NGINX configuration file
  • options: object
    • noComments: boolean - Strips all comments from the AST

generateConfig (ast)

Generates and returns configuration code from an abstract tree.

Arguments

  • ast: object - Abstract tree for an NGINX configuration