forked from Matt-Esch/string-template
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcustom.js
More file actions
47 lines (34 loc) · 896 Bytes
/
custom.js
File metadata and controls
47 lines (34 loc) · 896 Bytes
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
38
39
40
41
42
43
44
45
46
47
var opTag = "{";
var clTag = "}";
var nargs = /\{([0-9a-zA-Z]+)\}/g
function isSpecialRegExpChar( c ) {
return "\^$.|?*+()[]{}".indexOf( c ) != -1;
}
function escapeForRegExp( str ) {
var l = str.length;
var result = "";
for( var i=0; i<l; i++ ) {
result += ( isSpecialRegExpChar( str[i] ) ? "\\" : "" ) + str[i];
}
return result;
}
function setOpenCloseTags( op, cl ) {
if( op == cl ) {
console.log( "ERROR: In setOpenCloseTags, open and close tags must be different to each other." );
return;
}
opTag = op;
clTag = cl;
var op_RegExp, cl_RegExp;
op_RegExp = escapeForRegExp( op );
cl_RegExp = escapeForRegExp( cl );
nargs = new RegExp( op_RegExp+"([0-9a-zA-Z]+)"+cl_RegExp, "g" );
}
module.exports.config = function() {
return {
opTag: opTag,
clTag: clTag,
nargs: nargs
}
}
module.exports.setOpenCloseTags = setOpenCloseTags;