{"id":43642,"library":"poor-mans-t-sql-formatter","title":"Poor Man's T-SQL Formatter","description":"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.","status":"active","version":"1.6.10","language":"javascript","source_language":"en","source_url":"https://github.com/TaoK/poor-mans-t-sql-formatter-npm-package","tags":["javascript","sql","formatter","sql formatter","tsql","formatting","minimizer","obfuscator","pretty-printer"],"install":[{"cmd":"npm install poor-mans-t-sql-formatter","lang":"bash","label":"npm"},{"cmd":"yarn add poor-mans-t-sql-formatter","lang":"bash","label":"yarn"},{"cmd":"pnpm add poor-mans-t-sql-formatter","lang":"bash","label":"pnpm"}],"dependencies":[],"imports":[{"note":"The library exports a single named function. CommonJS require() returns the module object, not the function directly.","wrong":"const formatSql = require('poor-mans-t-sql-formatter')","symbol":"formatSql","correct":"import { formatSql } from 'poor-mans-t-sql-formatter'"},{"note":"There is no default export. Use named import or const { formatSql } = require('...').","wrong":"const pmtsqf = require('poor-mans-t-sql-formatter').default","symbol":"default","correct":"import pmtsqf from 'poor-mans-t-sql-formatter'"},{"note":"The wrong pattern is actually correct here. This is the CommonJS destructuring pattern.","wrong":"const formatSql = require('poor-mans-t-sql-formatter').formatSql; const result = formatSql(sql, { indent: '  ' });","symbol":"formatSql with options","correct":"const { formatSql } = require('poor-mans-t-sql-formatter'); const result = formatSql(sql, { indent: '  ', maxLineWidth: 120 });"}],"quickstart":{"code":"const { formatSql } = require('poor-mans-t-sql-formatter');\nconst sql = 'select * from users where id = 1';\nconst result = formatSql(sql, { indent: '  ', maxLineWidth: 80, trailingCommas: false });\nconsole.log(result.text);","lang":"javascript","description":"Demonstrates basic formatting of a simple SQL query with indentation and line width options."},"warnings":[{"fix":"Use the original C# library or command-line tool for large-scale formatting tasks.","message":"The library is about 8x slower than the original C# version. Avoid using it for formatting large batches of SQL files.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Install both: npm install poor-mans-t-sql-formatter poor-mans-t-sql-formatter-cli","message":"The 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.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Parse the result.text and look for '--WARNING' or '--ERROR' comments.","message":"The result object's 'text' property may contain warning comments if parsing failed. Always check for errors.","severity":"gotcha","affected_versions":">=1.0.0"},{"fix":"Update import from const fmt = require('poor-mans-t-sql-formatter'); fmt(...) to const { formatSql } = require('poor-mans-t-sql-formatter'); formatSql(...)","message":"Breaking change: In older versions (<1.6.0), the module exported a function directly. Now it exports an object with formatSql.","severity":"breaking","affected_versions":"<1.6.0"}],"env_vars":null,"search_vec":"'1.6.10':34 '8x':83 'api':68 'approxim':82 'batch':95 'browser':62 'c':15,88 'code':32 'command':99 'command-lin':98 'differenti':54 'distribut':103 'format':25,43,72,114 'formatt':7,22,110,112 'function':50 'html':75 'interfac':101 'javascript':10,58,108 'javascript-n':57 'key':53 'larg':94 'latest':37 'librari':11,23,89 'line':100 'list':77 'make':90 'man':2,17 'minim':44,115 'multipl':70 'nativ':59 'node.js':64 'obfusc':46,116 'option':52 'origin':87 'output':71 'packag':107 'pars':78 'plain':73 'poor':1,16 'pretti':118 'pretty-print':117 'printer':119 'process':96 'provid':41 'pure':9 'releas':39 'separ':106 'simpl':67 'singl':49 'slower':84 'sql':6,21,28,31,42,109,111 'stabl':38 't-sql':4,19,26 'text':74 'token':76 'transact':30 'transact-sql':29 'transpil':12 'tree':79 'tsql':113 'unsuit':92 'version':33 'via':47 'work':60","created_at":"2026-06-05T17:00:46.646781+00:00","updated_at":"2026-06-05T17:00:46.646781+00:00","problems":[{"fix":"Use named import: import { formatSql } from 'poor-mans-t-sql-formatter'","cause":"Default import in TypeScript/ESM when there is no default export.","error":"TypeError: poor_man_s_t_sql_formatter_1.default is not a function"},{"fix":"Run: npm install poor-mans-t-sql-formatter","cause":"Package not installed or incorrect require path.","error":"Error: Cannot find module 'poor-mans-t-sql-formatter'"},{"fix":"Ensure includeText: true (default) in options, or check for result.text existence.","cause":"formatSql returns an object with text property only if includeText option is true (default). Other properties like html exist if includeHtml is true.","error":"undefined is not an object (evaluating 'result.text')"}],"ecosystem":"npm","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":null,"cli_name":null,"cli_version":null,"type":"library","homepage":"https://github.com/TaoK/poor-mans-t-sql-formatter-npm-package#readme","github":"https://github.com/TaoK/poor-mans-t-sql-formatter-npm-package","docs":null,"changelog":null,"pypi":null,"npm":"poor-mans-t-sql-formatter","openapi_spec":null,"status_page":null,"smithery":null,"categories":["devops"],"base_url":null,"auth_type":null,"provenance":{"verified_status":null,"verified_at":null,"last_verified":"2026-06-05","next_check":"2026-09-03","install_tag":null}}