@jaredwray/fumanchu
Version:
Handlebars + Helpers = Fumanchu
106 lines (102 loc) • 3.6 kB
TypeScript
import { CacheableMemory, CacheableMemoryOptions } from '@cacheable/memory';
export { CacheableMemory, CacheableMemoryOptions } from '@cacheable/memory';
import HandlebarsLib from 'handlebars';
type Helper = {
name: string;
category: string;
compatibility?: string[];
fn: ((...arguments_: any[]) => string) | ((...arguments_: any[]) => number) | ((...arguments_: any[]) => boolean) | ((...arguments_: any[]) => unknown) | ((...arguments_: any[]) => number | string) | ((...arguments_: any[]) => HandlebarsLib.SafeString);
};
type HelperFilter = {
names?: string[];
categories?: string[];
compatibility?: string[];
};
declare class HelperRegistry {
private readonly _helpers;
constructor();
/**
* Get all registered helpers.
* @returns {Helper[]} The array of registered helpers.
*/
get helpers(): Helper[];
/**
* Initialize the helper registry. This is performed during the construction of the registry such as new HelperRegistry().
*/
init(): void;
/**
* Register a helper.
* @param {Helper} helper The helper to register.
* @returns True if the helper was registered, false otherwise.
*/
register(helper: Helper): boolean;
/**
* Register multiple helpers.
* @param {Helper[]} helpers The array of helpers to register.
*/
registerHelpers(helpers: Helper[]): void;
/**
* Check if a helper is registered.
* @param name The name of the helper.
* @returns True if the helper is registered, false otherwise.
*/
has(name: string): boolean;
/**
* Filter helpers by the given criteria.
* @param filter The filter criteria.
* @returns The filtered helpers.
*/
filter(filter: HelperFilter): Helper[];
/**
* Load Handlebars helpers.
* @param {Handlebars} handlebars The Handlebars instance.
* @returns {void}
*/
load(handlebars: any, filters?: HelperFilter): void;
/**
* Swap Handlebars helpers. This is used when you want to swap out legacy helpers for fumanchu helpers.
* @param handlebars The Handlebars instance.
* @returns {void}
*/
swap(handlebars: any): void;
}
/**
* Handlebars library not initiated with helpers
* @type {Handlebars}
*/
declare const Handlebars: typeof HandlebarsLib;
/**
* Fumanchu Handlebars instance not initiated with helpers
* @type {Handlebars}
*/
declare const handlebars: typeof HandlebarsLib;
/**
* Fumanchu Handlebars helpers
*/
type HelpersOptions = {
handlebars?: typeof HandlebarsLib;
hbs?: typeof HandlebarsLib;
};
/**
* Register Handlebars helpers
* @param {HelpersOptions} options - Options for Fumanchu helpers
*/
declare function helpers(options: HelpersOptions): void;
/**
* Create a new Handlebars instance with Fumanchu helpers
* @returns {Promise<Handlebars>}
* @deprecated Will be deprecated in future versions, use `fumanchu()` instead.
*/
declare function createHandlebars(): Promise<typeof HandlebarsLib>;
type FumanchuOptions = {
handlebars?: typeof HandlebarsLib;
filter?: HelperFilter;
caching?: boolean | CacheableMemory | CacheableMemoryOptions;
};
/**
* Will return a Handlebars instance with Fumanchu helpers (experimental)
* @param {FumanchuOptions} [options] - Options for Fumanchu
* @returns {Handlebars} Handlebars instance with helpers
*/
declare function fumanchu(options?: FumanchuOptions): typeof HandlebarsLib;
export { type FumanchuOptions, Handlebars, type HelperFilter, HelperRegistry, type HelpersOptions, createHandlebars, fumanchu, handlebars, helpers };