npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

sql-format-plus

v0.0.2

Published

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

Readme

sql-format-plus

English README

sql-format-plus 是一个轻量级 JavaScript 和 TypeScript SQL 格式化库。

它支持:

  • Standard SQL
  • Couchbase N1QL
  • IBM DB2
  • Oracle PL/SQL

功能特性

  • 使用 TypeScript 编写,并内置打包后的类型声明
  • 输出 ESM 和 UMD 构建产物
  • 支持自定义缩进
  • 支持命名占位符和索引占位符替换
  • 按 SQL 方言配置 tokenizer
  • 使用 VitePress 生成文档
  • 使用 Vite 提供本地 demo

安装

npm install sql-format-plus
pnpm add sql-format-plus

快速开始

import sqlFormatter from 'sql-format-plus'

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

输出:

SELECT
  *
FROM
  table1

也可以使用命名导出:

import { format } from 'sql-format-plus'

format('SELECT * FROM table1', {
  language: 'sql',
  indent: '    ',
})

占位符替换

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)

| 参数 | 类型 | 默认值 | 说明 | | ---------- | --------------------------------------------------------------------------------------------------- | ----------- | ------------------------ | | language | 'sql' \| 'n1ql' \| 'db2' \| 'pl/sql' | 'sql' | SQL 方言配置。 | | indent | string | ' ' | 一个缩进层级使用的字符。 | | params | Record<string, string \| number \| boolean \| null> \| Array<string \| number \| boolean \| null> | undefined | 占位符替换值。 |

CDN / UMD 用法

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

构建产物说明

发布包包含:

  • dist/sql-format-plus.es.js:给现代 bundler 使用的 ESM 版本
  • dist/sql-format-plus.umd.js:给 script 标签或传统接入方式使用的 UMD 版本
  • dist/sql-format-plus.umd.min.js:压缩后的 UMD 版本
  • types/sql-format-plus.d.ts:打包后的 TypeScript 类型声明

源码映射文件和 CommonJS 构建产物不会进入最终发布包。

本地开发

pnpm install
pnpm run dev
pnpm run check
pnpm run build

项目结构

  • src/sql-format-plus/index.ts:库入口
  • src/sql-format-plus/core:分词、格式化、缩进、内联块和参数替换逻辑
  • src/sql-format-plus/languages:不同 SQL 方言的 formatter 配置
  • src/main.ts:本地 demo 入口
  • rollup.config.cjs:库构建和类型打包配置
  • vite.config.mts:demo 开发配置
  • docs:VitePress 文档

License

MIT