UNPKG

@alexop/openapi-zod-client

Version:

[![Screenshot 2022-11-12 at 18 52 25](https://user-images.githubusercontent.com/47224540/201487856-ffc4c862-6f31-4de1-8ef1-3981fabf3416.png)](https://openapi-zod-client.vercel.app/)

44 lines (37 loc) 1.33 kB
import type { HelperOptions } from "handlebars"; import { create } from "handlebars"; export const getHandlebars = () => { const instance = create(); instance.registerHelper("ifeq", function (a: string, b: string, options: HelperOptions) { if (a === b) { // @ts-expect-error return options.fn(this); } // @ts-expect-error return options.inverse(this); }); instance.registerHelper("ifNotEmptyObj", function (obj: Record<string, any>, options: HelperOptions) { if (typeof obj === "object" && Object.keys(obj).length > 0) { // @ts-expect-error return options.fn(this); } // @ts-expect-error return options.inverse(this); }); instance.registerHelper("toCamelCase", function (input: string) { // Check if input string is already in camelCase if (/^[a-z][a-zA-Z0-9]*$/.test(input)) { return input } 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; };