Registry / devops / pg-formatter

pg-formatter

JSON →
library2.0.8jsnpmunverified

A PostgreSQL SQL syntax beautifier that is a thin Node.js wrapper around the Perl-based pgFormatter (https://github.com/darold/pgFormatter). Version 2.0.8 is current stable; released via npm, maintained by Gajus Kuizinas. Requires Perl on the host system. Ships TypeScript type definitions. Supports customizable formatting options like keyword/function case, indentation spaces/tabs, comma breaking, anonymization, placeholder regex, and comment stripping. Provides both programmatic API and CLI tool. Key differentiators: leverages the mature pgFormatter Perl engine, supports all PostgreSQL-specific syntax, configurable via options map matching pgFormatter flags.

npm install pg-formatter
INSTALL
IMPORT
SIG · PG-FORMATTER
P
pg-formatter
devopsjavascriptv2.0.8
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

format
import { format } from 'pg-formatter'
const format = require('pg-formatter');
ESM-only since v2. CommonJS require() fails.
format (default)
import pgFormatter from 'pg-formatter'; pgFormatter.format(sql);
import pgFormatter from 'pg-formatter'; pgFormatter(sql);
Package does not export a default function; must access .format method.
format
const { format } = await import('pg-formatter');
const { format } = require('pg-formatter');
For dynamic imports, use ESM dynamic import().

Demonstrates basic usage of format() with options for keyword case and indentation.

import { format } from 'pg-formatter'; const sql = 'SELECT foo, bar FROM baz WHERE id = 1 ORDER BY name'; const formatted = format(sql, { keywordCase: 'uppercase', spaces: 2 }); console.log(formatted); // Output: // SELECT // foo, // bar // FROM // baz // WHERE // id = 1 // ORDER BY // name
Debug
Known issues
gotchaRequires Perl on the host system. Without Perl, the module throws an error at runtime.
fix
Install Perl (e.g., via apt-get install perl or brew install perl).
affects: >=1.0 <3.0
breakingVersion 2.0 dropped CommonJS support. All imports must use ESM syntax.
fix
Use import { format } from 'pg-formatter' instead of require().
affects: >=2.0
gotchaOptions use camelCase in JavaScript but kebab-case in CLI (e.g., commaBreak vs comma-break). Mismatch can cause silent fallback to defaults.
fix
Use camelCase for programmatic API, kebab-case for CLI flags.
affects: >=1.0 <3.0
gotchaThe spaces option is ignored when tabs is true. Setting both may produce unexpected output.
fix
Set either spaces or tabs, not both.
affects: >=1.0 <3.0
deprecatedThe no-rcfile option is deprecated in favor of noRcFile (camelCase) in programmatic API. Both work but camelCase is preferred.
fix
Use noRcFile: true instead of no-rcfile.
affects: >=2.0 <3.0
Errors
Common errors & fixes
Error: Cannot find module 'pg-formatter'
Missing npm installation or incorrect import path.
fix
Run npm install pg-formatter and verify the import: import { format } from 'pg-formatter';
Internal error: Perl is not installed or not in PATH
pg-formatter requires Perl to run the underlying pgFormatter.
fix
Install Perl (sudo apt-get install perl on Ubuntu, brew install perl on macOS).
TypeError: pg_formatter_1.default is not a function
Trying to call module as a function instead of accessing .format method.
fix
Use import { format } from 'pg-formatter' and call format(sql).
Error: Cannot use 'import.meta' outside a module
Running ESM code in a CommonJS context (e.g., .js file without "type": "module").
fix
Add "type": "module" to package.json or use .mjs extension.
Upgrade
Version history
2.0.8latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
11 hits · last 30 days
node
10
Resources
pg-formatter — npm install pg-formatter · libregistry