🚀 Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more
Socket
Book a DemoInstallSign in
Socket

nginx-config-formatter

Package Overview
Dependencies
Maintainers
1
Versions
9
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

nginx-config-formatter

A formatter for Nginx config files

1.4.5
latest
Source
npm
Version published
Maintainers
1
Created
Source

Nginx Config Formatter

NPM version NPM Downloads License Minified Size Build Status

A formatter for Nginx config files. Both API and CLI are available.

Features

Features from nginxbeautifier

  • all lines are indented in an uniform manner, with 4 spaces per level
  • neighbouring empty lines are collapsed to at most two empty lines
  • curly braces placement follows Java convention
  • whitespaces are collapsed, except in comments and quotation marks

Plus we have:

  • empty lines after { or before } are trimmed
  • an API with full TypeScript support
  • tests to ensure consistency

CLI Usage

npm i -g nginx-config-formatter

Or

pnpm i -g nginx-config-formatter
nginx-config-formatter -p /etc/nginx

available options:
-p, --path (required)          the path of files to be formatted. Support glob syntax
-h, --help                     display usage help
-i, --indentStyle              style of indentation, space or tab, defaults to space
-c, --dontJoinCurlyBracket     if true, the opening bracket starts with a new line, defaults to false
-a, --align                    align the values of all directives in the same block, defaults to false
-l, --trailingBlankLines       Append a trailing blank line after the opening bracket, defaults to false
-ext, --extension              the file extension of nginx config files, defaults to conf

API Usage

formatFile(path: string, options?: OptionType): Promise<void>

path can be the path of a .conf file, or a folder contains .conf file. Glob syntax is also supported. If a folder is provided, all .conf files including those in its sub folders will be formatted.

formatContent(content: string, options?: OptionType): string

content is the full content of a config file. Returns a string of the formatted content.

The APIs above accepts a option object. All options are optional and its default value is the same as the CLI.

interface OptionType {
    indentStyle?: 'space' | 'tab'
    dontJoinCurlyBracket?: boolean
    align?: boolean
    trailingBlankLines?: boolean
    extension?: string
}

Example

import { formatFile } from 'nginx-config-formatter'

formatFile('/etc/nginx', {
    indentStyle: 'tab'
})

Changelog

See CHANGELOG

Credits

This project is inspired by nginxbeautifier and use some of its code.

Acknowledgment

If you found it useful somehow, I would be grateful if you could leave a star in the project's GitHub repository.

Thank you.

FAQs

Package last updated on 15 Oct 2023

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts