Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

esm support for handlebarhelpers #47

Merged
merged 2 commits into from
Jun 17, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 26 additions & 3 deletions index.d.ts
Original file line number Diff line number Diff line change
@@ -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 };
11 changes: 8 additions & 3 deletions index.mjs
Original file line number Diff line number Diff line change
Expand Up @@ -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 };

Loading