sql-format-plus 0.0.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/LICENSE ADDED
@@ -0,0 +1,22 @@
1
+ The MIT License (MIT)
2
+
3
+ Copyright (c) 2016-present ZeroTurnaround LLC
4
+ Copyright (c) 2026-present xcy960815 <18763006837@163.com>
5
+
6
+ Permission is hereby granted, free of charge, to any person obtaining a copy
7
+ of this software and associated documentation files (the "Software"), to deal
8
+ in the Software without restriction, including without limitation the rights
9
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
10
+ copies of the Software, and to permit persons to whom the Software is
11
+ furnished to do so, subject to the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be included in all
14
+ copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
17
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
18
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
19
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
20
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
21
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
22
+ SOFTWARE.
package/README.md ADDED
@@ -0,0 +1,134 @@
1
+ # sql-format-plus
2
+
3
+ [中文文档](./README.zh-CN.md)
4
+
5
+ - Documentation: [https://xcy960815.github.io/sql-format-plus/](https://xcy960815.github.io/sql-format-plus/)
6
+ - Online Demo: [https://xcy960815.github.io/sql-format-plus/guide/demo](https://xcy960815.github.io/sql-format-plus/guide/demo)
7
+
8
+ `sql-format-plus` is a lightweight JavaScript and TypeScript library for pretty-printing SQL queries.
9
+
10
+ It supports:
11
+
12
+ - Standard SQL
13
+ - Couchbase N1QL
14
+ - IBM DB2
15
+ - Oracle PL/SQL
16
+
17
+ ## Features
18
+
19
+ - TypeScript source and bundled declaration files
20
+ - ESM and UMD build artifacts
21
+ - Configurable indentation
22
+ - Named and indexed placeholder replacement
23
+ - Dialect-specific tokenizer configuration
24
+ - VitePress documentation
25
+ - Local Vite demo
26
+
27
+ ## Installation
28
+
29
+ ```bash
30
+ npm install sql-format-plus
31
+ ```
32
+
33
+ ```bash
34
+ pnpm add sql-format-plus
35
+ ```
36
+
37
+ ## Quick Start
38
+
39
+ ```ts
40
+ import sqlFormatter from 'sql-format-plus'
41
+
42
+ console.log(sqlFormatter.format('SELECT * FROM table1'))
43
+ ```
44
+
45
+ Output:
46
+
47
+ ```sql
48
+ SELECT
49
+ *
50
+ FROM
51
+ table1
52
+ ```
53
+
54
+ You can also use the named export:
55
+
56
+ ```ts
57
+ import { format } from 'sql-format-plus'
58
+
59
+ format('SELECT * FROM table1', {
60
+ language: 'sql',
61
+ indent: ' ',
62
+ })
63
+ ```
64
+
65
+ ## Placeholder Replacement
66
+
67
+ ```ts
68
+ import { format } from 'sql-format-plus'
69
+
70
+ format('SELECT * FROM tbl WHERE foo = @foo', {
71
+ params: {
72
+ foo: "'bar'",
73
+ },
74
+ })
75
+ ```
76
+
77
+ ```ts
78
+ format('SELECT * FROM tbl WHERE foo = ?', {
79
+ params: ["'bar'"],
80
+ })
81
+ ```
82
+
83
+ ## API
84
+
85
+ ### `format(query, options)`
86
+
87
+ | Option | Type | Default | Description |
88
+ | ---------- | --------------------------------------------------------------------------------------------------- | ----------- | ------------------------------------------ |
89
+ | `language` | `'sql' \| 'n1ql' \| 'db2' \| 'pl/sql'` | `'sql'` | SQL dialect configuration. |
90
+ | `indent` | `string` | `' '` | Characters used for one indentation level. |
91
+ | `params` | `Record<string, string \| number \| boolean \| null> \| Array<string \| number \| boolean \| null>` | `undefined` | Placeholder replacement values. |
92
+
93
+ ## CDN / UMD Example
94
+
95
+ ```html
96
+ <script src="https://unpkg.com/sql-format-plus/dist/sql-format-plus.umd.min.js"></script>
97
+ <script>
98
+ const result = window.SqlFormatPlus.format('SELECT * FROM table1')
99
+ </script>
100
+ ```
101
+
102
+ ## Build Artifacts
103
+
104
+ The published package includes:
105
+
106
+ - `dist/sql-format-plus.es.js`: ESM build for modern bundlers
107
+ - `dist/sql-format-plus.umd.js`: UMD build for script-tag or legacy integration
108
+ - `dist/sql-format-plus.umd.min.js`: minified UMD build
109
+ - `types/sql-format-plus.d.ts`: bundled TypeScript declarations
110
+
111
+ Source maps and CommonJS output are intentionally not published.
112
+
113
+ ## Development
114
+
115
+ ```bash
116
+ pnpm install
117
+ pnpm run dev
118
+ pnpm run check
119
+ pnpm run build
120
+ ```
121
+
122
+ ## Project Structure
123
+
124
+ - `src/sql-format-plus/index.ts`: library entry
125
+ - `src/sql-format-plus/core`: tokenizer, formatter, indentation, inline-block, and params logic
126
+ - `src/sql-format-plus/languages`: dialect-specific formatter configuration
127
+ - `src/main.ts`: local demo entry
128
+ - `rollup.config.js`: Rollup build for library bundles and bundled declarations
129
+ - `vite.config.mts`: Vite config for the demo app
130
+ - `docs`: VitePress documentation
131
+
132
+ ## License
133
+
134
+ [MIT](./LICENSE)
@@ -0,0 +1,134 @@
1
+ # sql-format-plus
2
+
3
+ [English README](./README.md)
4
+
5
+ - 文档地址:[https://xcy960815.github.io/sql-format-plus/](https://xcy960815.github.io/sql-format-plus/)
6
+ - 在线演示:[https://xcy960815.github.io/sql-format-plus/zh-CN/guide/demo](https://xcy960815.github.io/sql-format-plus/zh-CN/guide/demo)
7
+
8
+ `sql-format-plus` 是一个轻量级 JavaScript 和 TypeScript SQL 格式化库。
9
+
10
+ 它支持:
11
+
12
+ - Standard SQL
13
+ - Couchbase N1QL
14
+ - IBM DB2
15
+ - Oracle PL/SQL
16
+
17
+ ## 功能特性
18
+
19
+ - 使用 TypeScript 编写,并内置打包后的类型声明
20
+ - 输出 ESM 和 UMD 构建产物
21
+ - 支持自定义缩进
22
+ - 支持命名占位符和索引占位符替换
23
+ - 按 SQL 方言配置 tokenizer
24
+ - 使用 VitePress 生成文档
25
+ - 使用 Vite 提供本地 demo
26
+
27
+ ## 安装
28
+
29
+ ```bash
30
+ npm install sql-format-plus
31
+ ```
32
+
33
+ ```bash
34
+ pnpm add sql-format-plus
35
+ ```
36
+
37
+ ## 快速开始
38
+
39
+ ```ts
40
+ import sqlFormatter from 'sql-format-plus'
41
+
42
+ console.log(sqlFormatter.format('SELECT * FROM table1'))
43
+ ```
44
+
45
+ 输出:
46
+
47
+ ```sql
48
+ SELECT
49
+ *
50
+ FROM
51
+ table1
52
+ ```
53
+
54
+ 也可以使用命名导出:
55
+
56
+ ```ts
57
+ import { format } from 'sql-format-plus'
58
+
59
+ format('SELECT * FROM table1', {
60
+ language: 'sql',
61
+ indent: ' ',
62
+ })
63
+ ```
64
+
65
+ ## 占位符替换
66
+
67
+ ```ts
68
+ import { format } from 'sql-format-plus'
69
+
70
+ format('SELECT * FROM tbl WHERE foo = @foo', {
71
+ params: {
72
+ foo: "'bar'",
73
+ },
74
+ })
75
+ ```
76
+
77
+ ```ts
78
+ format('SELECT * FROM tbl WHERE foo = ?', {
79
+ params: ["'bar'"],
80
+ })
81
+ ```
82
+
83
+ ## API
84
+
85
+ ### `format(query, options)`
86
+
87
+ | 参数 | 类型 | 默认值 | 说明 |
88
+ | ---------- | --------------------------------------------------------------------------------------------------- | ----------- | ------------------------ |
89
+ | `language` | `'sql' \| 'n1ql' \| 'db2' \| 'pl/sql'` | `'sql'` | SQL 方言配置。 |
90
+ | `indent` | `string` | `' '` | 一个缩进层级使用的字符。 |
91
+ | `params` | `Record<string, string \| number \| boolean \| null> \| Array<string \| number \| boolean \| null>` | `undefined` | 占位符替换值。 |
92
+
93
+ ## CDN / UMD 用法
94
+
95
+ ```html
96
+ <script src="https://unpkg.com/sql-format-plus/dist/sql-format-plus.umd.min.js"></script>
97
+ <script>
98
+ const result = window.SqlFormatPlus.format('SELECT * FROM table1')
99
+ </script>
100
+ ```
101
+
102
+ ## 构建产物说明
103
+
104
+ 发布包包含:
105
+
106
+ - `dist/sql-format-plus.es.js`:给现代 bundler 使用的 ESM 版本
107
+ - `dist/sql-format-plus.umd.js`:给 script 标签或传统接入方式使用的 UMD 版本
108
+ - `dist/sql-format-plus.umd.min.js`:压缩后的 UMD 版本
109
+ - `types/sql-format-plus.d.ts`:打包后的 TypeScript 类型声明
110
+
111
+ 源码映射文件和 CommonJS 构建产物不会进入最终发布包。
112
+
113
+ ## 本地开发
114
+
115
+ ```bash
116
+ pnpm install
117
+ pnpm run dev
118
+ pnpm run check
119
+ pnpm run build
120
+ ```
121
+
122
+ ## 项目结构
123
+
124
+ - `src/sql-format-plus/index.ts`:库入口
125
+ - `src/sql-format-plus/core`:分词、格式化、缩进、内联块和参数替换逻辑
126
+ - `src/sql-format-plus/languages`:不同 SQL 方言的 formatter 配置
127
+ - `src/main.ts`:本地 demo 入口
128
+ - `rollup.config.js`:库构建和类型打包配置
129
+ - `vite.config.mts`:demo 开发配置
130
+ - `docs`:VitePress 文档
131
+
132
+ ## License
133
+
134
+ [MIT](./LICENSE)