super-utils-plus
Version:
A superior alternative to Lodash with improved performance, TypeScript support, and developer experience
27 lines (26 loc) • 917 B
TypeScript
import { TemplateOptions } from '../utils/types';
/**
* Creates a compiled template function that can interpolate data properties
* in "interpolate" delimiters, HTML-escape interpolated data properties in
* "escape" delimiters, and execute JavaScript in "evaluate" delimiters.
*
* @param string - The template string
* @param options - The options object
* @returns The compiled template function
*
* @example
* ```ts
* // Use the default delimiters: <%= value %>, <%- value %>, <% code %>
* const compiled = template('hello <%= user %>!');
* compiled({ 'user': 'fred' });
* // => 'hello fred!'
*
* // Use custom delimiters
* const compiled = template('hello {{user}}!', {
* interpolate: /{{([\s\S]+?)}}/g
* });
* compiled({ 'user': 'fred' });
* // => 'hello fred!'
* ```
*/
export declare function template(string: string, options?: TemplateOptions): (data?: Record<string, any>) => string;