lodash之模板设置

templateSettings

今天在看lodash的typescript定义文件时,发现有这么一处定义:

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
declare namespace _ {
interface LoDashStatic {

}

/**
* By default, the template delimiters used by Lo-Dash are similar to those in embedded Ruby
*默认像ruby里的嵌入式
* (ERB). Change the following template settings to use alternative delimiters.
**/

interface TemplateSettings {
/**
* The "escape" delimiter.
**/

escape?: RegExp;

/**
* The "evaluate" delimiter.
**/

evaluate?: RegExp;

/**
* An object to import into the template as local variables.
**/

imports?: Dictionary<any>;

/**
* The "interpolate" delimiter.
**/

interpolate?: RegExp;

/**
* Used to reference the data object in the template text.
**/

variable?: string;
}
}

我们看到lodash的官网上有这么一处举例:

`js // using custom template delimiters(分隔符) _.templateSettings.interpolate = /undefined/g; var compiled = _.template('hello !'); compiled({ 'user': 'mustache' }); // => 'hello mustache!'

欢迎关注我的公众号:沉迷Spring
显示 Gitment 评论
0%