JSPM

sql-format-plus

0.0.2
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 296
  • Score
    100M100P100Q10506F
  • License MIT

Formats whitespaces in a SQL query to make it more readable.

Package Exports

  • sql-format-plus

Readme

sql-format-plus

中文文档

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-plus
pnpm add sql-format-plus

Quick Start

import sqlFormatter from 'sql-format-plus'

console.log(sqlFormatter.format('SELECT * FROM table1'))

Output:

SELECT
  *
FROM
  table1

You 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 bundlers
  • dist/sql-format-plus.umd.js: UMD build for script-tag or legacy integration
  • dist/sql-format-plus.umd.min.js: minified UMD build
  • types/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 build

Project Structure

  • src/sql-format-plus/index.ts: library entry
  • src/sql-format-plus/core: tokenizer, formatter, indentation, inline-block, and params logic
  • src/sql-format-plus/languages: dialect-specific formatter configuration
  • src/main.ts: local demo entry
  • rollup.config.cjs: Rollup build for library bundles and bundled declarations
  • vite.config.mts: Vite config for the demo app
  • docs: VitePress documentation

License

MIT