quicktype-core 23.0.167 → 23.0.168
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.
|
@@ -24,7 +24,7 @@ import { type RenderContext } from "../../Renderer";
|
|
|
24
24
|
import { EnumOption, type Option, StringOption } from "../../RendererOptions";
|
|
25
25
|
import { type NamingStyle } from "../../support/Strings";
|
|
26
26
|
import { TargetLanguage } from "../../TargetLanguage";
|
|
27
|
-
import { type
|
|
27
|
+
import { type FixMeOptionsAnyType, type FixMeOptionsType } from "../../types";
|
|
28
28
|
import { CJSONRenderer } from "./CJSONRenderer";
|
|
29
29
|
export declare const cJSONOptions: {
|
|
30
30
|
typeSourceStyle: EnumOption<boolean>;
|
|
@@ -71,7 +71,7 @@ class RustRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
71
71
|
emitRenameAttribute(propName, jsonName, defaultNamingStyle, preferedNamingStyle) {
|
|
72
72
|
const escapedName = (0, utils_1.rustStringEscape)(jsonName);
|
|
73
73
|
const name = utils_1.namingStyles[defaultNamingStyle].fromParts(this.sourcelikeToString(propName).split(" "));
|
|
74
|
-
const styledName = (0, utils_1.
|
|
74
|
+
const styledName = (0, utils_1.nameWithNamingStyle)(name, preferedNamingStyle);
|
|
75
75
|
const namesDiffer = escapedName !== styledName;
|
|
76
76
|
if (namesDiffer) {
|
|
77
77
|
this.emitLine('#[serde(rename = "', escapedName, '")]');
|
|
@@ -103,7 +103,7 @@ class RustRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
103
103
|
});
|
|
104
104
|
// Set the default naming style on the struct
|
|
105
105
|
const defaultStyle = "snake_case";
|
|
106
|
-
const preferedNamingStyle = (0, utils_1.
|
|
106
|
+
const preferedNamingStyle = (0, utils_1.getPreferredNamingStyle)(Object.values(propertiesNamingStyles).flat(), defaultStyle);
|
|
107
107
|
if (preferedNamingStyle !== defaultStyle) {
|
|
108
108
|
this.emitLine(`#[serde(rename_all = "${preferedNamingStyle}")]`);
|
|
109
109
|
}
|
|
@@ -148,7 +148,7 @@ class RustRenderer extends ConvenienceRenderer_1.ConvenienceRenderer {
|
|
|
148
148
|
});
|
|
149
149
|
// Set the default naming style on the enum
|
|
150
150
|
const defaultStyle = "PascalCase";
|
|
151
|
-
const preferedNamingStyle = (0, utils_1.
|
|
151
|
+
const preferedNamingStyle = (0, utils_1.getPreferredNamingStyle)(Object.values(enumCasesNamingStyles).flat(), defaultStyle);
|
|
152
152
|
if (preferedNamingStyle !== defaultStyle) {
|
|
153
153
|
this.emitLine(`#[serde(rename_all = "${preferedNamingStyle}")]`);
|
|
154
154
|
}
|
|
@@ -7,18 +7,52 @@ export declare enum Visibility {
|
|
|
7
7
|
Crate = "Crate",
|
|
8
8
|
Public = "Public"
|
|
9
9
|
}
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
10
|
+
export declare const namingStyles: {
|
|
11
|
+
readonly snake_case: {
|
|
12
|
+
readonly regex: RegExp;
|
|
13
|
+
readonly toParts: (name: string) => string[];
|
|
14
|
+
readonly fromParts: (parts: string[]) => string;
|
|
15
|
+
};
|
|
16
|
+
readonly SCREAMING_SNAKE_CASE: {
|
|
17
|
+
readonly regex: RegExp;
|
|
18
|
+
readonly toParts: (name: string) => string[];
|
|
19
|
+
readonly fromParts: (parts: string[]) => string;
|
|
20
|
+
};
|
|
21
|
+
readonly camelCase: {
|
|
22
|
+
readonly regex: RegExp;
|
|
23
|
+
readonly toParts: (name: string) => string[];
|
|
24
|
+
readonly fromParts: (parts: string[]) => string;
|
|
25
|
+
};
|
|
26
|
+
readonly PascalCase: {
|
|
27
|
+
readonly regex: RegExp;
|
|
28
|
+
readonly toParts: (name: string) => string[];
|
|
29
|
+
readonly fromParts: (parts: string[]) => string;
|
|
30
|
+
};
|
|
31
|
+
readonly "kebab-case": {
|
|
32
|
+
readonly regex: RegExp;
|
|
33
|
+
readonly toParts: (name: string) => string[];
|
|
34
|
+
readonly fromParts: (parts: string[]) => string;
|
|
35
|
+
};
|
|
36
|
+
readonly "SCREAMING-KEBAB-CASE": {
|
|
37
|
+
readonly regex: RegExp;
|
|
38
|
+
readonly toParts: (name: string) => string[];
|
|
39
|
+
readonly fromParts: (parts: string[]) => string;
|
|
40
|
+
};
|
|
41
|
+
readonly lowercase: {
|
|
42
|
+
readonly regex: RegExp;
|
|
43
|
+
readonly toParts: (name: string) => string[];
|
|
44
|
+
readonly fromParts: (parts: string[]) => string;
|
|
45
|
+
};
|
|
46
|
+
readonly UPPERCASE: {
|
|
47
|
+
readonly regex: RegExp;
|
|
48
|
+
readonly toParts: (name: string) => string[];
|
|
49
|
+
readonly fromParts: (parts: string[]) => string;
|
|
50
|
+
};
|
|
51
|
+
};
|
|
52
|
+
export type NamingStyleKey = keyof typeof namingStyles;
|
|
18
53
|
export declare const snakeNamingFunction: import("../../Naming").Namer;
|
|
19
54
|
export declare const camelNamingFunction: import("../../Naming").Namer;
|
|
20
55
|
export declare const rustStringEscape: (s: string) => string;
|
|
21
|
-
export declare function
|
|
22
|
-
export declare function listMatchingNamingStyles(name: string):
|
|
23
|
-
export declare function
|
|
24
|
-
export {};
|
|
56
|
+
export declare function getPreferredNamingStyle(namingStyleOccurences: string[], defaultStyle: NamingStyleKey): NamingStyleKey;
|
|
57
|
+
export declare function listMatchingNamingStyles(name: string): NamingStyleKey[];
|
|
58
|
+
export declare function nameWithNamingStyle(name: string, style: NamingStyleKey): string;
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.
|
|
3
|
+
exports.nameWithNamingStyle = exports.listMatchingNamingStyles = exports.getPreferredNamingStyle = exports.rustStringEscape = exports.camelNamingFunction = exports.snakeNamingFunction = exports.namingStyles = exports.Visibility = exports.Density = void 0;
|
|
4
4
|
const Naming_1 = require("../../Naming");
|
|
5
5
|
const Strings_1 = require("../../support/Strings");
|
|
6
6
|
var Density;
|
|
@@ -58,6 +58,7 @@ exports.namingStyles = {
|
|
|
58
58
|
fromParts: (parts) => parts.map(p => p.toUpperCase()).join("")
|
|
59
59
|
}
|
|
60
60
|
};
|
|
61
|
+
exports.namingStyles;
|
|
61
62
|
const isAsciiLetterOrUnderscoreOrDigit = (codePoint) => {
|
|
62
63
|
if (!(0, Strings_1.isAscii)(codePoint)) {
|
|
63
64
|
return false;
|
|
@@ -88,26 +89,22 @@ const standardUnicodeRustEscape = (codePoint) => {
|
|
|
88
89
|
}
|
|
89
90
|
};
|
|
90
91
|
exports.rustStringEscape = (0, Strings_1.utf32ConcatMap)((0, Strings_1.escapeNonPrintableMapper)(Strings_1.isPrintable, standardUnicodeRustEscape));
|
|
91
|
-
function
|
|
92
|
+
function getPreferredNamingStyle(namingStyleOccurences, defaultStyle) {
|
|
92
93
|
const occurrences = Object.fromEntries(Object.keys(exports.namingStyles).map(key => [key, 0]));
|
|
93
94
|
namingStyleOccurences.forEach(style => ++occurrences[style]);
|
|
94
95
|
const max = Math.max(...Object.values(occurrences));
|
|
95
|
-
const preferedStyles = Object.entries(occurrences)
|
|
96
|
-
.filter(([_style, num]) => num === max)
|
|
97
|
-
.map(([style, _num]) => style);
|
|
96
|
+
const preferedStyles = Object.entries(occurrences).flatMap(([style, num]) => num === max ? [style] : []);
|
|
98
97
|
if (preferedStyles.includes(defaultStyle)) {
|
|
99
98
|
return defaultStyle;
|
|
100
99
|
}
|
|
101
100
|
return preferedStyles[0];
|
|
102
101
|
}
|
|
103
|
-
exports.
|
|
102
|
+
exports.getPreferredNamingStyle = getPreferredNamingStyle;
|
|
104
103
|
function listMatchingNamingStyles(name) {
|
|
105
|
-
return Object.entries(exports.namingStyles)
|
|
106
|
-
.filter(([_, { regex }]) => regex.test(name))
|
|
107
|
-
.map(([namingStyle, _]) => namingStyle);
|
|
104
|
+
return Object.entries(exports.namingStyles).flatMap(([namingStyleKey, { regex }]) => regex.test(name) ? [namingStyleKey] : []);
|
|
108
105
|
}
|
|
109
106
|
exports.listMatchingNamingStyles = listMatchingNamingStyles;
|
|
110
|
-
function
|
|
107
|
+
function nameWithNamingStyle(name, style) {
|
|
111
108
|
if (exports.namingStyles[style].regex.test(name)) {
|
|
112
109
|
return name;
|
|
113
110
|
}
|
|
@@ -117,4 +114,4 @@ function nameToNamingStyle(name, style) {
|
|
|
117
114
|
}
|
|
118
115
|
return exports.namingStyles[style].fromParts(exports.namingStyles[fromStyle].toParts(name));
|
|
119
116
|
}
|
|
120
|
-
exports.
|
|
117
|
+
exports.nameWithNamingStyle = nameWithNamingStyle;
|