ts-proto 1.93.2 → 1.93.3

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 CHANGED
@@ -1,3 +1,10 @@
1
+ ## [1.93.3](https://github.com/stephenh/ts-proto/compare/v1.93.2...v1.93.3) (2021-12-13)
2
+
3
+
4
+ ### Bug Fixes
5
+
6
+ * support mutliple options in snakeToCamel flag ([#429](https://github.com/stephenh/ts-proto/issues/429)) ([cff6674](https://github.com/stephenh/ts-proto/commit/cff667406cba21676546fd91b04cf2cbc571ed7d)), closes [#423](https://github.com/stephenh/ts-proto/issues/423)
7
+
1
8
  ## [1.93.2](https://github.com/stephenh/ts-proto/compare/v1.93.1...v1.93.2) (2021-12-09)
2
9
 
3
10
 
package/README.markdown CHANGED
@@ -289,9 +289,7 @@ Generated code will be placed in the Gradle build directory.
289
289
 
290
290
  - With `--ts_proto_opt=lowerCaseServiceMethods=true`, the method names of service methods will be lowered/camel-case, i.e. `service.findFoo` instead of `service.FindFoo`.
291
291
 
292
- - With `--ts_proto_opt=snakeToCamel=false`, fields will be kept snake case.
293
-
294
- Defaults to `true`.
292
+ - With `--ts_proto_opt=snakeToCamel=false`, fields will be kept snake case. `snakeToCamel` can also be set as string with `--ts_proto_opt=snakeToCamel=keys,json`. `keys` will keep field names as camelCase and `json` will keep json field names as camelCase. Empty string will keep field names as snake_case.
295
293
 
296
294
  - With `--ts_proto_opt=outputEncodeMethods=false`, the `Message.encode` and `Message.decode` methods for working with protobuf-encoded/binary data will not be output.
297
295
 
package/build/case.js CHANGED
@@ -1,8 +1,10 @@
1
1
  "use strict";
2
2
  Object.defineProperty(exports, "__esModule", { value: true });
3
- exports.camelCase = exports.capitalize = exports.camelToSnake = exports.maybeSnakeToCamel = void 0;
3
+ exports.camelCase = exports.capitalize = exports.camelToSnake = exports.stringToSnakeCase = exports.maybeSnakeToCamel = void 0;
4
4
  function maybeSnakeToCamel(s, options) {
5
- if (options.snakeToCamel && s.includes('_')) {
5
+ const fromStringSnakeToCamel = typeof options.snakeToCamel === 'string' && options.snakeToCamel.includes('keys');
6
+ const fromBooleanSnakeToCamel = options.snakeToCamel === true;
7
+ if ((fromBooleanSnakeToCamel || fromStringSnakeToCamel) && s.includes('_')) {
6
8
  return s
7
9
  .split('_')
8
10
  .map((word, i) => {
@@ -21,6 +23,10 @@ function maybeSnakeToCamel(s, options) {
21
23
  }
22
24
  }
23
25
  exports.maybeSnakeToCamel = maybeSnakeToCamel;
26
+ function stringToSnakeCase(s) {
27
+ return s.replace(/([a-z])([A-Z])/g, '$1_$2').toLowerCase();
28
+ }
29
+ exports.stringToSnakeCase = stringToSnakeCase;
24
30
  function camelToSnake(s) {
25
31
  return s
26
32
  .replace(/[\w]([A-Z])/g, function (m) {
package/build/utils.js CHANGED
@@ -147,10 +147,12 @@ exports.FormattedMethodDescriptor = FormattedMethodDescriptor;
147
147
  function determineFieldJsonName(field, options) {
148
148
  // By default jsonName is camelCased by the protocol compilier unless the user has
149
149
  // set a "json_name" option on this field.
150
- if (field.jsonName.length > 0) {
150
+ const fromStringSnakeToCamel = typeof options.snakeToCamel === 'string' && options.snakeToCamel.includes('json');
151
+ const fromBooleanSnakeToCamel = options.snakeToCamel === true;
152
+ if (fromBooleanSnakeToCamel || fromStringSnakeToCamel) {
151
153
  return field.jsonName;
152
154
  }
153
- return case_1.maybeSnakeToCamel(field.name, options);
155
+ return case_1.stringToSnakeCase(field.name);
154
156
  }
155
157
  exports.determineFieldJsonName = determineFieldJsonName;
156
158
  function impProto(options, module, type) {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "ts-proto",
3
- "version": "1.93.2",
3
+ "version": "1.93.3",
4
4
  "description": "",
5
5
  "main": "build/plugin.js",
6
6
  "repository": "github:stephenh/ts-proto",