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 🙏

© 2026 – Pkg Stats / Ryan Hefner

@guojc1/sql-formatter-compact

v1.1.0

Published

A compact, highly customizable SQL formatter with flush-left keywords support.

Readme

Note: This is a highly customized fork of sql-formatter designed for extreme compactness and relative flush-left alignment (especially for WHERE, AND, FROM clauses, and WITH statement bug fixes). It supports placing commas before fields (commaPosition: 'before') without breaking trailing inline comments.

🇨🇳 查看中文特性说明 (README_zh.md)

Installation: npm install @guojc1/sql-formatter-compact

SQL Formatter Compact

SQL Formatter Compact is a JavaScript library and CLI tool for strict, clean, and highly customizable pretty-printing of SQL queries.

Install

Get the latest version from NPM:

npm install -g @guojc1/sql-formatter-compact

Usage

Usage as library

import { format } from '@guojc1/sql-formatter-compact';

console.log(
  format('SELECT * FROM tbl', {
    language: 'mysql',
    commaPosition: 'before',
    newlineAfterClause: false,
  })
);

Magic Comments (Ignore Formatting)

You can disable formatting for specific sections of your SQL code by wrapping them in these magic comments:

/* sql-formatter-compact-disable */
SELECT    *   FROM      tbl1;
/* sql-formatter-compact-enable */

Usage from command line (CLI)

The CLI tool will be installed as sql-formatter-compact:

sql-formatter-compact -h
usage: sql-formatter-compact-cli.cjs [-h] [-o OUTPUT] [--fix] [-l {bigquery,clickhouse,db2,hive,mysql,postgresql,spark,sql,sqlite,trino...}] [-c CONFIG] [--version] [FILE]

positional arguments:
  FILE                  Input SQL file (defaults to stdin)

optional arguments:
  -h, --help            show this help message and exit
  -o OUTPUT, --output OUTPUT
                        File to write SQL output (defaults to stdout)
  --fix                 Update the file in-place
  -l ..., --language ...
                        SQL Formatter dialect (defaults to basic sql)
  -c CONFIG, --config CONFIG
                        Path to config JSON file or json string (will find a file named '.sql-formatter-compact.json' or use default configs if unspecified)
  --version             show program's version number and exit

Formatting in-place

To format a file and overwrite its contents directly, use the --fix flag along with your configuration file (-c):

sql-formatter-compact -c ./sqlfmt.json --fix ./src/queries/my_query.sql

By default, the tool takes queries from stdin and processes them to stdout.

Configuration options

The tool accepts a JSON config file named .sql-formatter-compact.json in the current or any parent directory. It supports all standard options from the original library, plus our custom commaPosition and newlineAfterClause options.

{
  "language": "spark",
  "tabWidth": 2,
  "keywordCase": "upper",
  "commaPosition": "before",
  "newlineAfterClause": false
}

License

MIT License. Core tokenization engine and parsing rules are based on the original sql-formatter by ZeroTurnaround LLC and Rene Saarsoo.