From 4cece3b2943099c78993e53546bc96ec9c064aa5 Mon Sep 17 00:00:00 2001 From: Jared Wray Date: Mon, 17 Jun 2024 09:15:04 -0600 Subject: [PATCH 1/2] esm support for handlebarhelpers --- index.mjs | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/index.mjs b/index.mjs index 387fc17..e2c619a 100644 --- a/index.mjs +++ b/index.mjs @@ -2,10 +2,15 @@ import HandlebarsLib from 'handlebars'; const handlebars = HandlebarsLib.create(); +// Variable to hold the helpers function +let handlebarHelpers; + import('./helpers.js').then((module) => { - const helpers = module.default; - helpers({ handlebars: handlebars }); - }); + handlebarHelpers = module.default; + handlebarHelpers({ handlebars: handlebars }); +}); // Exporting for ESM export default handlebars; +export { handlebarHelpers }; + From 151d9b085fe26f59d14dc3dcbd0a30c16f692ffe Mon Sep 17 00:00:00 2001 From: Jared Wray Date: Mon, 17 Jun 2024 09:31:36 -0600 Subject: [PATCH 2/2] Update index.d.ts --- index.d.ts | 29 ++++++++++++++++++++++++++--- 1 file changed, 26 insertions(+), 3 deletions(-) diff --git a/index.d.ts b/index.d.ts index 93f146c..4ebf20d 100644 --- a/index.d.ts +++ b/index.d.ts @@ -1,3 +1,26 @@ -// index.d.ts -import * as Handlebars from 'handlebars'; -export = Handlebars; +// Import necessary types from the Handlebars library +import { HelperDelegate, HandlebarsLib as HandlebarsNamespace } from 'handlebars'; + +// Define a type for the Handlebars instance +export interface HandlebarsInstance extends HandlebarsNamespace { + create: () => HandlebarsInstance; + registerHelper: (name: string, fn: HelperDelegate) => void; +} + +// Define the type for the parameters of the helpers function +interface HelpersParams { + handlebars: HandlebarsInstance; +} + +// Define the type for the helpers function +declare function helpers(params: HelpersParams): void; + +// Declare the variable to hold the helpers function, which may be undefined initially +declare let handlebarHelpers: typeof helpers | undefined; + +// Declare the Handlebars instance as a HandlebarsInstance and export it as the default export +declare const handlebars: HandlebarsInstance; +export default handlebars; + +// Export the helpers function as a named export +export { handlebarHelpers };