Registry / devops / poor-mans-t-sql-formatter

poor-mans-t-sql-formatter

JSON →
library1.6.10jsnpmunverified

A pure JavaScript library, transpiled from the C# Poor Man's T-SQL Formatter library, for formatting T-SQL (Transact-SQL) code. Version 1.6.10 is the latest stable release. It provides SQL formatting, minimization, and obfuscation via a single function with options. Key differentiators: it's JavaScript-native (works in browser and Node.js), has a simple API with multiple output formats (plain text, HTML, token list, parse tree), but is approximately 8x slower than the original C# library, making it unsuitable for large batch processing. The command-line interface is distributed as a separate package.

npm install poor-mans-t-sql-formatter
INSTALL
IMPORT
SIG · POOR-MANS-T-SQL-FO
P
poor-mans-t-sql-formatter
devopsjavascriptv1.6.10
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.

formatSql
import { formatSql } from 'poor-mans-t-sql-formatter'
const formatSql = require('poor-mans-t-sql-formatter')
The library exports a single named function. CommonJS require() returns the module object, not the function directly.
default
import pmtsqf from 'poor-mans-t-sql-formatter'
const pmtsqf = require('poor-mans-t-sql-formatter').default
There is no default export. Use named import or const { formatSql } = require('...').
formatSql with options
const { formatSql } = require('poor-mans-t-sql-formatter'); const result = formatSql(sql, { indent: ' ', maxLineWidth: 120 });
const formatSql = require('poor-mans-t-sql-formatter').formatSql; const result = formatSql(sql, { indent: ' ' });
The wrong pattern is actually correct here. This is the CommonJS destructuring pattern.

Demonstrates basic formatting of a simple SQL query with indentation and line width options.

const { formatSql } = require('poor-mans-t-sql-formatter'); const sql = 'select * from users where id = 1'; const result = formatSql(sql, { indent: ' ', maxLineWidth: 80, trailingCommas: false }); console.log(result.text);
Debug
Known issues
gotchaThe library is about 8x slower than the original C# version. Avoid using it for formatting large batches of SQL files.
fix
Use the original C# library or command-line tool for large-scale formatting tasks.
affects: >=1.0.0
gotchaThe command-line interface is in a separate npm package (poor-mans-t-sql-formatter-cli). Installing this package alone does not give you a CLI.
fix
Install both: npm install poor-mans-t-sql-formatter poor-mans-t-sql-formatter-cli
affects: >=1.0.0
gotchaThe result object's 'text' property may contain warning comments if parsing failed. Always check for errors.
fix
Parse the result.text and look for '--WARNING' or '--ERROR' comments.
affects: >=1.0.0
breakingBreaking change: In older versions (<1.6.0), the module exported a function directly. Now it exports an object with formatSql.
fix
Update import from const fmt = require('poor-mans-t-sql-formatter'); fmt(...) to const { formatSql } = require('poor-mans-t-sql-formatter'); formatSql(...)
affects: <1.6.0
Errors
Common errors & fixes
TypeError: poor_man_s_t_sql_formatter_1.default is not a function
Default import in TypeScript/ESM when there is no default export.
fix
Use named import: import { formatSql } from 'poor-mans-t-sql-formatter'
Error: Cannot find module 'poor-mans-t-sql-formatter'
Package not installed or incorrect require path.
fix
Run: npm install poor-mans-t-sql-formatter
undefined is not an object (evaluating 'result.text')
formatSql returns an object with text property only if includeText option is true (default). Other properties like html exist if includeHtml is true.
fix
Ensure includeText: true (default) in options, or check for result.text existence.
Upgrade
Version history
1.6.10latest on npm
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
poor-mans-t-sql-formatter — npm install poor-mans-t-sql-formatter · libregistry