File tree Expand file tree Collapse file tree
tools/proto-convert/src/postprocessing Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -130,21 +130,23 @@ function isVersionedName(name: string): boolean {
130130}
131131
132132/**
133- * Convert PascalCase/camelCase type name to snake_case.
134- * e.g., "TermsAggregation" -> "terms_aggregation"
133+ * Convert a name to snake_case variable name format.
135134 */
136- function toSnakeCase ( typeName : string ) : string {
137- return typeName
138- . replace ( / ( [ A - Z ] ) / g, '_$1' )
139- . toLowerCase ( )
140- . replace ( / ^ _ / , '' ) ;
135+ function toVarName ( name : string ) : string {
136+ name = name . replace ( / ^ _ + / , '' ) ;
137+
138+ return name
139+ . replace ( / ( [ A - Z ] + ) ( [ A - Z ] [ a - z ] ) / g, '$1_$2' )
140+ . replace ( / ( [ a - z 0 - 9 ] ) ( [ A - Z ] ) / g, '$1_$2' )
141+ . replace ( / ( \d ) ( [ A - Z a - z ] ) / g, '$1_$2' )
142+ . toLowerCase ( ) ;
141143}
142144
143145/**
144146 * Check if field name is the formatted (snake_case) version of the type name.
145147 */
146148function isFormattedName ( fieldName : string , typeName : string ) : boolean {
147- return fieldName === toSnakeCase ( typeName ) ;
149+ return fieldName === toVarName ( typeName ) ;
148150}
149151
150152/** Check if message has any oneof with fields */
You can’t perform that action at this time.
0 commit comments