Skip to content

Commit

Permalink
fix: normalize enum names (#29)
Browse files Browse the repository at this point in the history
  • Loading branch information
chrisdickinson authored Oct 14, 2024
1 parent c9de0eb commit 1fb7126
Showing 1 changed file with 8 additions and 1 deletion.
9 changes: 8 additions & 1 deletion template/src/pdk.ts.ejs
Original file line number Diff line number Diff line change
Expand Up @@ -57,7 +57,14 @@ export class <%- schema.name %> {
*/
export enum <%- schema.name %> {
<% schema.enum.forEach(variant => { -%>
<%- variant %> = "<%- variant %>",
<%- variant
// "host:foo$bar" -> "host_Foo$bar"
.replace(/[^a-zA-Z0-9_$]+(.)?/g, (a, m) => '_' + (m ||'').toUpperCase())
// "13" -> "$13" ("$" is a valid identifier char; with apologies to jquery)
.replace(/^([^a-zA-Z_$])/, (a, m) => `$${m}`)
// "host_Foo_Bar" -> "Host_Foo_Bar"
.replace(/^(.)/, (a, m) => m.toUpperCase())
%> = "<%- variant %>",
<% }) -%>
}
Expand Down

0 comments on commit 1fb7126

Please sign in to comment.