|
1
|
|
|
/** |
|
2
|
|
|
* escape a regex |
|
3
|
|
|
* @param {String} str |
|
4
|
|
|
* @param {String} params g,m,i |
|
|
|
|
|
|
5
|
|
|
* @return {Object} RegExp |
|
6
|
|
|
*/ |
|
7
|
|
|
export function getAttr (str, attr) { |
|
8
|
|
|
var rex = new RegExp(attr + '=["|\']([\\S\\s]*?)["|\']( +[a-zA-Z0-9-]*?=|}})') |
|
9
|
|
|
var res = rex.exec(str) |
|
10
|
|
|
res = (res != null && res.length > 1) ? res[1] : '' |
|
11
|
|
|
return res |
|
12
|
|
|
} |
|
13
|
|
|
|
|
14
|
|
|
/** |
|
15
|
|
|
* escape a regex |
|
16
|
|
|
* @param {String} str |
|
17
|
|
|
* @param {String} params g,m,i |
|
18
|
|
|
* @return {Object} RegExp |
|
19
|
|
|
*/ |
|
20
|
|
|
export function escapeTextToRegex(str, params) { |
|
21
|
|
|
str = str.replace(/[-\/\\^$*+?.()|[\]{}]/g, '\\$&') |
|
22
|
|
|
return new RegExp(str, params) |
|
23
|
|
|
} |
|
24
|
|
|
|
|
25
|
|
|
/** |
|
26
|
|
|
* Test if a string don't contains string key from ABE block statement |
|
27
|
|
|
* @param {String} str string to test |
|
28
|
|
|
* @return {Boolean} true = this is not a block content |
|
29
|
|
|
*/ |
|
30
|
|
|
export function isSingleAbe(str, text){ |
|
31
|
|
|
return !new RegExp('#each(.)+?' + getAttr(str, 'key').split('.')[0]).test(text) && |
|
32
|
|
|
str.indexOf('{{#') < 0 && |
|
33
|
|
|
str.indexOf('#each') < 0 && |
|
34
|
|
|
str.indexOf('{{/') < 0 && |
|
35
|
|
|
str.indexOf('/each') < 0 && |
|
36
|
|
|
str.indexOf('attrAbe') < 0 |
|
37
|
|
|
} |
|
38
|
|
|
|
|
39
|
|
|
/** |
|
40
|
|
|
* Test if a string contains string key from ABE block statement |
|
41
|
|
|
* @param {String} str string to test |
|
42
|
|
|
* @return {Boolean} true = this is a block content |
|
43
|
|
|
*/ |
|
44
|
|
|
export function isBlockAbe(str) { |
|
45
|
|
|
return str.indexOf('abe') > -1 && getAttr(str, 'key').indexOf('.') > -1 |
|
46
|
|
|
} |
|
47
|
|
|
|
|
48
|
|
|
/** |
|
49
|
|
|
* Test if a string contains string key from {{#each}} block statement |
|
50
|
|
|
* @param {String} str string to test |
|
51
|
|
|
* @return {Boolean} true = this is a block content |
|
52
|
|
|
*/ |
|
53
|
|
|
export function isEachStatement(str) { |
|
54
|
|
|
return str.indexOf('#each') > -1 || str.indexOf('/each') > -1 |
|
55
|
|
|
} |
|
56
|
|
|
|
|
57
|
|
|
/** |
|
58
|
|
|
* Test if a string contains string key from {{#each}} block statement |
|
59
|
|
|
* @param {String} str string to test |
|
|
|
|
|
|
60
|
|
|
* @return {Boolean} true = this is a block content |
|
61
|
|
|
*/ |
|
62
|
|
|
export function getTagAbeTypeRequest(text) { |
|
63
|
|
|
let listReg = /({{abe.*type=[\'|\"]data.*}})/g |
|
64
|
|
|
var matches = [] |
|
65
|
|
|
var match |
|
66
|
|
|
while (match = listReg.exec(text)) { |
|
67
|
|
|
matches.push(match) |
|
68
|
|
|
} |
|
69
|
|
|
return matches |
|
70
|
|
|
} |
|
71
|
|
|
|
|
72
|
|
|
/** |
|
73
|
|
|
*/ |
|
74
|
|
|
export function getTagAbeWithType(text, type) { |
|
75
|
|
|
var listReg = new RegExp(`({{abe.*type=[\\'|\\"]${type}.*}})`, 'g') |
|
76
|
|
|
var matches = [] |
|
77
|
|
|
var match |
|
78
|
|
|
while (match = listReg.exec(text)) { |
|
79
|
|
|
matches.push(match[0]) |
|
80
|
|
|
} |
|
81
|
|
|
return matches |
|
82
|
|
|
} |
|
83
|
|
|
|
|
84
|
|
|
/** |
|
85
|
|
|
*/ |
|
86
|
|
|
export function getTagAbeWithTab(text, tab) { |
|
87
|
|
|
var listReg = new RegExp(`({{abe.*tab=[\\'|\\"]${tab}.*}})`, 'g') |
|
88
|
|
|
var matches = [] |
|
89
|
|
|
var match |
|
90
|
|
|
while (match = listReg.exec(text)) { |
|
91
|
|
|
matches.push(match[0]) |
|
92
|
|
|
} |
|
93
|
|
|
return matches |
|
94
|
|
|
} |
|
95
|
|
|
|
|
96
|
|
|
export function validDataAbe(str){ |
|
97
|
|
|
return str.replace(/\[([0-9]*)\]/g, '$1') |
|
98
|
|
|
} |