UNPKG

dynamic-content-html

Version:

A dynamic content html processing library for template interpolation with rich content support

95 lines (90 loc) 3.9 kB
interface DynamicTextConfig { variableFormat?: { start: string; end: string; }; } interface DynamicTextOptions { [key: string]: any; } type RichContentFunction = (chunks: string) => string; interface RichTextOptions extends DynamicTextOptions { [key: string]: RichContentFunction | any; } interface MJMLOptions extends DynamicTextOptions { [key: string]: any; } interface MJMLConfig extends DynamicTextConfig { mjmlAttributes?: boolean; mjmlTextContent?: boolean; } /** * Main Dynamic Content Html function - similar to i18n t() function * @param template - Template string with variable placeholders * @param options - Object containing variable values * @param config - Optional configuration for variable format * @returns Processed string with variables replaced * * @example * d('Hello {name}!', { name: 'Jane' }) // "Hello Jane!" (default format) * d('Hello {{name}}!', { name: 'Jane' }, { variableFormat: { start: '{{', end: '}}' } }) // "Hello Jane!" * d('Hello [name]!', { name: 'Jane' }, { variableFormat: { start: '[', end: ']' } }) // "Hello Jane!" */ declare function d(template: string, options?: DynamicTextOptions, config?: DynamicTextConfig): string; declare namespace d { var rich: typeof rich; var mjml: typeof mjml; } /** * Rich content function - similar to i18n rich() function * @param template - Template string with variable placeholders * @param options - Object containing variable values and rich content functions * @param config - Optional configuration for variable format * @returns Processed string with variables replaced and rich content applied * * @example * d.rich('Click {link} for more info', { * link: (chunks) => `<a href="/info">${chunks}</a>` * }) // "Click <a href="/info">link</a> for more info" * * d.rich('Click [[link]] for more info', { * link: (chunks) => `<a href="/info">${chunks}</a>` * }, { variableFormat: { start: '[[', end: ']]' } }) */ declare function rich(template: string, options?: RichTextOptions, config?: DynamicTextConfig): string; /** * MJML function - processes MJML content with dynamic data * @param template - MJML template string with variable placeholders * @param options - Object containing variable values * @param config - Optional configuration for variable format and MJML processing * @returns Processed MJML string with variables replaced * * @example * d.mjml('<mj-text>Hello {name}!</mj-text>', { name: 'Jane' }) * d.mjml('<mj-button href="{url}">Click here</mj-button>', { url: 'https://example.com' }) */ declare function mjml(template: string, options?: MJMLOptions, config?: MJMLConfig): string; /** * Extract variables from template string using custom format */ declare function extractVariables(template: string, config?: DynamicTextConfig): string[]; /** * Get nested property value from object using dot notation */ declare function getNestedValue(obj: any, path: string): any; /** * Replace variables in template with values from options using custom format */ declare function replaceVariables(template: string, options: DynamicTextOptions, config?: DynamicTextConfig): string; /** * Process rich content with HTML functions using custom format */ declare function processRichContent(template: string, options: DynamicTextOptions, richFunctions: Record<string, (chunks: string) => string>, config?: DynamicTextConfig): string; /** * Process MJML content with dynamic data * Handles both MJML attributes and text content */ declare function processMJML(template: string, options?: MJMLOptions, config?: MJMLConfig): string; //# sourceMappingURL=index.d.ts.map export { d, d as default, extractVariables, getNestedValue, mjml, processMJML, processRichContent, replaceVariables, rich }; export type { DynamicTextConfig, DynamicTextOptions, MJMLConfig, MJMLOptions, RichContentFunction, RichTextOptions };