npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

nginx-config-formatter

v1.4.5

Published

A formatter for Nginx config files

Downloads

2,530

Readme

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.