File tree Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Expand file tree Collapse file tree 1 file changed +10
-5
lines changed Original file line number Diff line number Diff line change @@ -99,7 +99,7 @@ function jsonToGo(json, typename)
99
99
100
100
function format ( str )
101
101
{
102
- return toProperCase ( str . replace ( / \s / g , "_" ) ) . replace ( / _ / g, "" ) ;
102
+ return toProperCase ( str ) . replace ( / \s | _ / g, "" ) ;
103
103
}
104
104
105
105
function goType ( val )
@@ -144,13 +144,18 @@ function jsonToGo(json, typename)
144
144
return "interface{}" ;
145
145
}
146
146
147
- // Thanks to http://stackoverflow.com/a/5574446/1048862
148
147
function toProperCase ( str )
149
148
{
150
- return str . replace ( / [ ^ _ ] * / gi, function ( txt )
149
+ if ( str . length == 0 )
150
+ return "" ;
151
+
152
+ str = str . charAt ( 0 ) . toUpperCase ( ) + str . substr ( 1 ) ;
153
+
154
+ return str . replace ( / [ \s _ ] [ a - z ] + / g, function ( txt )
151
155
{
152
- return txt . charAt ( 0 ) . toUpperCase ( )
153
- + txt . substr ( 1 ) . toLowerCase ( ) ;
156
+ return txt . charAt ( 0 )
157
+ + txt . charAt ( 1 ) . toUpperCase ( )
158
+ + txt . substr ( 2 ) . toLowerCase ( ) ;
154
159
} ) ;
155
160
}
156
161
}
You can’t perform that action at this time.
0 commit comments