pgsql-deparser 17.7.2 → 17.8.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/README.md +44 -2
- package/deparser.d.ts +2 -0
- package/deparser.js +363 -86
- package/esm/deparser.js +363 -86
- package/esm/utils/sql-formatter.js +11 -2
- package/package.json +2 -2
- package/utils/sql-formatter.d.ts +3 -1
- package/utils/sql-formatter.js +11 -2
|
@@ -1,15 +1,21 @@
|
|
|
1
1
|
export class SqlFormatter {
|
|
2
2
|
newlineChar;
|
|
3
3
|
tabChar;
|
|
4
|
-
|
|
4
|
+
prettyMode;
|
|
5
|
+
constructor(newlineChar = '\n', tabChar = ' ', prettyMode = false) {
|
|
5
6
|
this.newlineChar = newlineChar;
|
|
6
7
|
this.tabChar = tabChar;
|
|
8
|
+
this.prettyMode = prettyMode;
|
|
7
9
|
}
|
|
8
10
|
format(parts, separator = ' ') {
|
|
9
11
|
return parts.filter(part => part !== null && part !== undefined && part !== '').join(separator);
|
|
10
12
|
}
|
|
11
13
|
indent(text, count = 1) {
|
|
12
|
-
|
|
14
|
+
if (!this.prettyMode) {
|
|
15
|
+
return text;
|
|
16
|
+
}
|
|
17
|
+
const indentation = this.tabChar.repeat(count);
|
|
18
|
+
return text.split(this.newlineChar).map(line => line.trim() ? indentation + line : line).join(this.newlineChar);
|
|
13
19
|
}
|
|
14
20
|
parens(content) {
|
|
15
21
|
return `(${content})`;
|
|
@@ -20,4 +26,7 @@ export class SqlFormatter {
|
|
|
20
26
|
tab() {
|
|
21
27
|
return this.tabChar;
|
|
22
28
|
}
|
|
29
|
+
isPretty() {
|
|
30
|
+
return this.prettyMode;
|
|
31
|
+
}
|
|
23
32
|
}
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "pgsql-deparser",
|
|
3
|
-
"version": "17.
|
|
3
|
+
"version": "17.8.1",
|
|
4
4
|
"author": "Dan Lynch <pyramation@gmail.com>",
|
|
5
5
|
"description": "PostgreSQL AST Deparser",
|
|
6
6
|
"main": "index.js",
|
|
@@ -51,5 +51,5 @@
|
|
|
51
51
|
"dependencies": {
|
|
52
52
|
"@pgsql/types": "^17.6.1"
|
|
53
53
|
},
|
|
54
|
-
"gitHead": "
|
|
54
|
+
"gitHead": "cffd419f76ad6975c89e7e4f79972f7f27b0eab7"
|
|
55
55
|
}
|
package/utils/sql-formatter.d.ts
CHANGED
|
@@ -1,10 +1,12 @@
|
|
|
1
1
|
export declare class SqlFormatter {
|
|
2
2
|
private newlineChar;
|
|
3
3
|
private tabChar;
|
|
4
|
-
|
|
4
|
+
private prettyMode;
|
|
5
|
+
constructor(newlineChar?: string, tabChar?: string, prettyMode?: boolean);
|
|
5
6
|
format(parts: string[], separator?: string): string;
|
|
6
7
|
indent(text: string, count?: number): string;
|
|
7
8
|
parens(content: string): string;
|
|
8
9
|
newline(): string;
|
|
9
10
|
tab(): string;
|
|
11
|
+
isPretty(): boolean;
|
|
10
12
|
}
|
package/utils/sql-formatter.js
CHANGED
|
@@ -4,15 +4,21 @@ exports.SqlFormatter = void 0;
|
|
|
4
4
|
class SqlFormatter {
|
|
5
5
|
newlineChar;
|
|
6
6
|
tabChar;
|
|
7
|
-
|
|
7
|
+
prettyMode;
|
|
8
|
+
constructor(newlineChar = '\n', tabChar = ' ', prettyMode = false) {
|
|
8
9
|
this.newlineChar = newlineChar;
|
|
9
10
|
this.tabChar = tabChar;
|
|
11
|
+
this.prettyMode = prettyMode;
|
|
10
12
|
}
|
|
11
13
|
format(parts, separator = ' ') {
|
|
12
14
|
return parts.filter(part => part !== null && part !== undefined && part !== '').join(separator);
|
|
13
15
|
}
|
|
14
16
|
indent(text, count = 1) {
|
|
15
|
-
|
|
17
|
+
if (!this.prettyMode) {
|
|
18
|
+
return text;
|
|
19
|
+
}
|
|
20
|
+
const indentation = this.tabChar.repeat(count);
|
|
21
|
+
return text.split(this.newlineChar).map(line => line.trim() ? indentation + line : line).join(this.newlineChar);
|
|
16
22
|
}
|
|
17
23
|
parens(content) {
|
|
18
24
|
return `(${content})`;
|
|
@@ -23,5 +29,8 @@ class SqlFormatter {
|
|
|
23
29
|
tab() {
|
|
24
30
|
return this.tabChar;
|
|
25
31
|
}
|
|
32
|
+
isPretty() {
|
|
33
|
+
return this.prettyMode;
|
|
34
|
+
}
|
|
26
35
|
}
|
|
27
36
|
exports.SqlFormatter = SqlFormatter;
|