UNPKG

2.42 kBTypeScriptView Raw
1import { ResolveFn, ResolveFnAsync } from './renderer';
2import { Scope } from './get';
3import { ICompileOptions } from './compile';
4/**
5 * Replaces every {{varName}} inside the template with values from the scope
6 * parameter.
7 * @warning **When dealing with user input, always make sure to validate it.**
8 * @param template The template containing one or more {{varName}} as
9 * placeholders for values from the `scope` parameter.
10 * @param scope An object containing values for variable names from the the
11 * template. If it's omitted, we default to an empty object.
12 * Since functions are objects in javascript, the `scope` can technically be a
13 * function too but it won't be called. It'll be treated as an object and its
14 * properties will be used for the lookup.
15 * @param options same options as the [[compile]] function
16 * @throws any error that [[compile]] or [[Renderer.render]] may throw
17 * @returns Template where its variable names replaced with
18 * corresponding values.
19 */
20export declare function render(template: string, scope?: Scope, options?: ICompileOptions): string;
21/**
22 * Same as [[render]] but accepts a resolver function which will be responsible
23 * for returning a value for every varName.
24 * @param resolveFn a function that takes a variable name and resolves it to a value.
25 * The value can be a number, string or boolean. If it is not, it'll be "stringified".
26 * @throws any error that [[compile]] or [[Renderer.renderFn]] may throw
27 * @returns Template where its variable names replaced with what is returned from the resolver
28 * function for each varName.
29 */
30export declare function renderFn(template: string, resolveFn: ResolveFn, scope?: Scope, options?: ICompileOptions): string;
31/**
32 * Same as [[renderFn]] but supports asynchronous resolver functions
33 * (a function that returns a promise instead of the value).
34 * @param resolveFn an async function that takes a variable name and resolves it to a value.
35 * The value can be a number, string or boolean. If it is not, it'll be "stringified".
36 * @throws any error that [[compile]] or [[Renderer.renderFnAsync]] may throw
37 * @returns a promise that when resolved contains the template where its variable names replaced
38 * with what is returned from the resolver function for each varName.
39 */
40export declare function renderFnAsync(template: string, resolveFnAsync: ResolveFnAsync, scope?: Scope, options?: ICompileOptions): Promise<string>;