ts-proto 1.121.5 → 1.121.6
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/CHANGELOG.md +7 -0
- package/build/case.js +18 -17
- package/build/utils.js +5 -1
- package/package.json +1 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,3 +1,10 @@
|
|
|
1
|
+
## [1.121.6](https://github.com/stephenh/ts-proto/compare/v1.121.5...v1.121.6) (2022-08-14)
|
|
2
|
+
|
|
3
|
+
|
|
4
|
+
### Bug Fixes
|
|
5
|
+
|
|
6
|
+
* Use jsonName even with snakeToCamel=false. ([#653](https://github.com/stephenh/ts-proto/issues/653)) ([1144886](https://github.com/stephenh/ts-proto/commit/1144886ef43eaf97b780c7aafb2c123fd49b3fe5)), closes [#635](https://github.com/stephenh/ts-proto/issues/635)
|
|
7
|
+
|
|
1
8
|
## [1.121.5](https://github.com/stephenh/ts-proto/compare/v1.121.4...v1.121.5) (2022-08-08)
|
|
2
9
|
|
|
3
10
|
|
package/build/case.js
CHANGED
|
@@ -1,29 +1,30 @@
|
|
|
1
1
|
"use strict";
|
|
2
2
|
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
-
exports.camelCase = exports.capitalize = exports.camelToSnake = exports.maybeSnakeToCamel = void 0;
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
return
|
|
8
|
-
.split('_')
|
|
9
|
-
.map((word, i) => {
|
|
10
|
-
// If the word is already mixed case, leave the exist case as-is
|
|
11
|
-
word = hasLowerCase ? word : word.toLowerCase();
|
|
12
|
-
return i === 0 ? word : capitalize(word);
|
|
13
|
-
})
|
|
14
|
-
.join('');
|
|
3
|
+
exports.camelCase = exports.capitalize = exports.camelToSnake = exports.snakeToCamel = exports.maybeSnakeToCamel = void 0;
|
|
4
|
+
/** Converts `key` to TS/JS camel-case idiom, unless overridden not to. */
|
|
5
|
+
function maybeSnakeToCamel(key, options) {
|
|
6
|
+
if (options.snakeToCamel.includes('keys') && key.includes('_')) {
|
|
7
|
+
return snakeToCamel(key);
|
|
15
8
|
}
|
|
16
9
|
else {
|
|
17
|
-
return
|
|
10
|
+
return key;
|
|
18
11
|
}
|
|
19
12
|
}
|
|
20
13
|
exports.maybeSnakeToCamel = maybeSnakeToCamel;
|
|
21
|
-
function
|
|
14
|
+
function snakeToCamel(s) {
|
|
15
|
+
const hasLowerCase = !!s.match(/[a-z]/);
|
|
22
16
|
return s
|
|
23
|
-
.
|
|
24
|
-
|
|
17
|
+
.split('_')
|
|
18
|
+
.map((word, i) => {
|
|
19
|
+
// If the word is already mixed case, leave the existing case as-is
|
|
20
|
+
word = hasLowerCase ? word : word.toLowerCase();
|
|
21
|
+
return i === 0 ? word : capitalize(word);
|
|
25
22
|
})
|
|
26
|
-
.
|
|
23
|
+
.join('');
|
|
24
|
+
}
|
|
25
|
+
exports.snakeToCamel = snakeToCamel;
|
|
26
|
+
function camelToSnake(s) {
|
|
27
|
+
return s.replace(/\w([A-Z])/g, (m) => m[0] + '_' + m[1]).toUpperCase();
|
|
27
28
|
}
|
|
28
29
|
exports.camelToSnake = camelToSnake;
|
|
29
30
|
function capitalize(s) {
|
package/build/utils.js
CHANGED
|
@@ -151,7 +151,11 @@ function getFieldJsonName(field, options) {
|
|
|
151
151
|
return field.jsonName;
|
|
152
152
|
}
|
|
153
153
|
else {
|
|
154
|
-
|
|
154
|
+
// The user wants to keep snake case in the JSON, but we still want to see if the jsonName
|
|
155
|
+
// attribute is set as an explicit override.
|
|
156
|
+
const probableJsonName = (0, case_1.snakeToCamel)(field.name);
|
|
157
|
+
const isJsonNameSet = probableJsonName !== field.jsonName;
|
|
158
|
+
return isJsonNameSet ? field.jsonName : field.name;
|
|
155
159
|
}
|
|
156
160
|
}
|
|
157
161
|
exports.getFieldJsonName = getFieldJsonName;
|