UNPKG

@jaredwray/fumanchu

Version:
109 lines (108 loc) 3.28 kB
import { CacheableMemory, CacheableMemoryOptions } from "@cacheable/memory"; import HandlebarsLib from "handlebars"; //#region src/helper-registry-base.d.ts type Helper = { name: string; category: string; compatibility?: string[]; fn: (...arguments_: any[]) => any; }; type HelperFilter = { names?: string[]; categories?: string[]; compatibility?: string[]; }; /** * Base class for helper registries. Holds all state-management logic and * leaves `init()` empty so environment-specific subclasses decide which * helper sets to register. This lets the browser registry avoid importing * any Node-only helper files. */ declare class HelperRegistryBase { protected readonly _helpers: Helper[]; constructor(); /** * Get all registered helpers. */ get helpers(): Helper[]; /** * Initialize the helper registry. Overridden by subclasses. */ init(): void; /** * Register a helper. Returns true if the helper was added, false if a * helper with the same name was already present. */ register(helper: Helper): boolean; /** * Register multiple helpers. */ registerHelpers(helpers: Helper[]): void; /** * Check if a helper is registered. */ has(name: string): boolean; /** * Filter helpers by the given criteria. */ filter(filter: HelperFilter): Helper[]; /** * Load Handlebars helpers. */ load(handlebars: any, filters?: HelperFilter): void; /** * Swap Handlebars helpers. This is used when you want to swap out legacy * helpers for fumanchu helpers. */ swap(handlebars: any): void; } //#endregion //#region src/helper-registry-browser.d.ts /** * Browser-only helper registry. Registers every environment-neutral helper * and omits anything that depends on Node core modules (fs, path, logging, * markdown, node-only url/html/code helpers). */ declare class HelperRegistryBrowser extends HelperRegistryBase { init(): void; } //#endregion //#region src/index.browser.d.ts /** * 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 Fumanchu browser-safe Handlebars helpers. */ declare function helpers(options: HelpersOptions): void; /** * Create a new Handlebars instance with Fumanchu browser-safe 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; }; /** * Return a Handlebars instance with Fumanchu browser-safe helpers. */ declare function fumanchu(options?: FumanchuOptions): typeof HandlebarsLib; //#endregion export { CacheableMemory, type CacheableMemoryOptions, FumanchuOptions, Handlebars, type HelperFilter, HelperRegistryBrowser as HelperRegistry, HelpersOptions, createHandlebars, fumanchu, handlebars, helpers };