UNPKG

624 BJavaScriptView Raw
1/**
2 * 元数据中表达式需要的一些函数
3 */
4
5// {{***}}
6const reg = /^\s*\{{2}([\s\S]+)\}{2}\s*$/m
7
8// {{{***}}}
9const reg1 = /^\s*\{{3}([\s\S]+)\}{3}\s*$/m
10
11function isExpression(v) {
12 return reg.test(v) || reg1.test(v)
13}
14
15function getExpressionBody(v) {
16 if (reg1.test(v)) {
17 //去掉前后{{{ }}}
18 return v.replace(reg1, (word, group) => group)
19 }
20
21 if (reg.test(v)) {
22 //return + 去掉前后{{ }}
23 return "return " + v.replace(reg, (word, group) => group)
24 }
25
26 return v
27}
28
29export default {
30 isExpression,
31 getExpressionBody
32}
\No newline at end of file