Skip to content

Commit

Permalink
Add camelCase formatting to hbs files
Browse files Browse the repository at this point in the history
  • Loading branch information
PeterMK85 authored and astahmer committed Aug 16, 2023
1 parent ac157d6 commit f18e3ea
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 0 deletions.
5 changes: 5 additions & 0 deletions .changeset/support_camel_case_formatting_in_hbs.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,5 @@
---
"openapi-zod-client": patch
---

Add `camelCase` formatting to `hbs` files.
12 changes: 12 additions & 0 deletions lib/src/getHandlebars.ts
Original file line number Diff line number Diff line change
Expand Up @@ -21,6 +21,18 @@ export const getHandlebars = () => {
// @ts-expect-error
return options.inverse(this);
});
instance.registerHelper("toCamelCase", function (input: string) {
const words = input.split(/[\s_-]/);
return words
.map((word, index) => {
if (index === 0) {
return word.toLowerCase();
}

return word.charAt(0).toUpperCase() + word.slice(1).toLowerCase();
})
.join("");
});

return instance;
};

1 comment on commit f18e3ea

@vercel
Copy link

@vercel vercel bot commented on f18e3ea Aug 16, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please sign in to comment.