Registry / devops / sql-format

sql-format

JSON →
library2.3.2jsnpmunverified

SQL Formatter is a JavaScript library for pretty-printing SQL queries, supporting Standard SQL, Couchbase N1QL, IBM DB2, and Oracle PL/SQL dialects. Current stable version is 2.3.2, with maintenance releases over years. Key differentiator: lightweight, no dependencies, supports placeholder replacement (named and indexed). Lacks TypeScript support in v2 but widely used for formatting SQL in Node.js and browser. Alternatives exist (e.g., prettier-plugin-sql) but sql-formatter is simpler and more focused.

devops
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.

Package is ESM-only from v2? Actually CJS require works for v2. Use default import for ESM.

import sqlFormatter from 'sql-formatter';

In v2, default export is the format function. Named export also available.

import { format } from 'sql-formatter';

Use 'language' not 'lang'. Options are part of the main export.

sqlFormatter.format('SELECT *', { language: 'n1ql', indent: ' ' });

Demonstrates formatting SQL with parameter substitution for named placeholders.

import sqlFormatter from 'sql-formatter'; const sql = 'SELECT a, b, c FROM tbl WHERE foo = @foo ORDER BY bar DESC'; const formatted = sqlFormatter.format(sql, { language: 'sql', indent: ' ', params: { foo: "'baz'" } }); console.log(formatted); // Output: // SELECT // a, // b, // c // FROM // tbl // WHERE // foo = 'baz' // ORDER BY // bar DESC
Debug
Known footguns
gotchaplaceholders @foo (named) and ? (indexed) require explicit params configuration; otherwise they are left as-is.
gotchaIndentation defaults to 2 spaces, but may cause inconsistent formatting if mixed with tabs in existing code.
gotchaDialect support is limited to sql, n1ql, db2, pl/sql. Other SQL dialects or vendor-specific syntax may produce unexpected output.
deprecatedUsage via global window.sqlFormatter in browser is deprecated; prefer module bundlers.
gotchaThe library does not provide TypeScript type definitions; using in TypeScript project may require custom .d.ts file.
Upgrade
Version history

Breaking-change detection hasn't run for this library yet.

Audit
Security & dependencies

CVE tracking and dependency tree are planned for a later release.

Agent activity
0 hits · last 30 days

No traffic data recorded yet.

Resources