Package Exports
- sql-format-plus
Readme
sql-format-plus
- Documentation: https://xcy960815.github.io/sql-format-plus/
- Online Demo: https://xcy960815.github.io/sql-format-plus/guide/demo
sql-format-plus is a lightweight JavaScript and TypeScript library for pretty-printing SQL queries.
It supports:
- Standard SQL
- Couchbase N1QL
- IBM DB2
- Oracle PL/SQL
Features
- TypeScript source and bundled declaration files
- ESM and UMD build artifacts
- Configurable indentation
- Named and indexed placeholder replacement
- Dialect-specific tokenizer configuration
- VitePress documentation
- Local Vite demo
Installation
npm install sql-format-pluspnpm add sql-format-plusQuick Start
import sqlFormatter from 'sql-format-plus'
console.log(sqlFormatter.format('SELECT * FROM table1'))Output:
SELECT
*
FROM
table1You can also use the named export:
import { format } from 'sql-format-plus'
format('SELECT * FROM table1', {
language: 'sql',
indent: ' ',
})Placeholder Replacement
import { format } from 'sql-format-plus'
format('SELECT * FROM tbl WHERE foo = @foo', {
params: {
foo: "'bar'",
},
})format('SELECT * FROM tbl WHERE foo = ?', {
params: ["'bar'"],
})API
format(query, options)
| Option | Type | Default | Description |
|---|---|---|---|
language |
'sql' | 'n1ql' | 'db2' | 'pl/sql' |
'sql' |
SQL dialect configuration. |
indent |
string |
' ' |
Characters used for one indentation level. |
params |
Record<string, string | number | boolean | null> | Array<string | number | boolean | null> |
undefined |
Placeholder replacement values. |
CDN / UMD Example
<script src="https://unpkg.com/sql-format-plus/dist/sql-format-plus.umd.min.js"></script>
<script>
const result = window.SqlFormatPlus.format('SELECT * FROM table1')
</script>Build Artifacts
The published package includes:
dist/sql-format-plus.es.js: ESM build for modern bundlersdist/sql-format-plus.umd.js: UMD build for script-tag or legacy integrationdist/sql-format-plus.umd.min.js: minified UMD buildtypes/sql-format-plus.d.ts: bundled TypeScript declarations
Source maps and CommonJS output are intentionally not published.
Development
pnpm install
pnpm run dev
pnpm run check
pnpm run buildProject Structure
src/sql-format-plus/index.ts: library entrysrc/sql-format-plus/core: tokenizer, formatter, indentation, inline-block, and params logicsrc/sql-format-plus/languages: dialect-specific formatter configurationsrc/main.ts: local demo entryrollup.config.cjs: Rollup build for library bundles and bundled declarationsvite.config.mts: Vite config for the demo appdocs: VitePress documentation