@jayfong/x-server 2.4.1 → 2.4.2
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
|
@@ -9,15 +9,16 @@ class TemplateRendererService {
|
|
|
9
9
|
}
|
|
10
10
|
|
|
11
11
|
render(text, data, options) {
|
|
12
|
+
const enableCode = !!(options != null && options.code);
|
|
12
13
|
const keys = Object.keys(data);
|
|
13
14
|
|
|
14
15
|
for (const key of keys) {
|
|
15
16
|
text = typeof data[key] === 'function' ? text.replace(new RegExp(`\\{${key}(:.+?)?\\}`, 'g'), (_, params) => {
|
|
16
17
|
return data[key].call(null, ...(params ? params.substring(1) : '').split(','));
|
|
17
|
-
}) : text.replaceAll(`{${key}}`, data[key]);
|
|
18
|
+
}) : enableCode ? text.replace(new RegExp(`(?<!\\$)\\{${key}\\}`, 'g'), data[key]) : text.replaceAll(`{${key}}`, data[key]);
|
|
18
19
|
}
|
|
19
20
|
|
|
20
|
-
if (
|
|
21
|
+
if (enableCode) {
|
|
21
22
|
text = text.replace(/\{\{(.+?)\}\}/g, (_, code) => {
|
|
22
23
|
return eval(`
|
|
23
24
|
(() => {
|
|
@@ -4,15 +4,16 @@ export class TemplateRendererService {
|
|
|
4
4
|
}
|
|
5
5
|
|
|
6
6
|
render(text, data, options) {
|
|
7
|
+
const enableCode = !!(options != null && options.code);
|
|
7
8
|
const keys = Object.keys(data);
|
|
8
9
|
|
|
9
10
|
for (const key of keys) {
|
|
10
11
|
text = typeof data[key] === 'function' ? text.replace(new RegExp(`\\{${key}(:.+?)?\\}`, 'g'), (_, params) => {
|
|
11
12
|
return data[key].call(null, ...(params ? params.substring(1) : '').split(','));
|
|
12
|
-
}) : text.replaceAll(`{${key}}`, data[key]);
|
|
13
|
+
}) : enableCode ? text.replace(new RegExp(`(?<!\\$)\\{${key}\\}`, 'g'), data[key]) : text.replaceAll(`{${key}}`, data[key]);
|
|
13
14
|
}
|
|
14
15
|
|
|
15
|
-
if (
|
|
16
|
+
if (enableCode) {
|
|
16
17
|
text = text.replace(/\{\{(.+?)\}\}/g, (_, code) => {
|
|
17
18
|
return eval(`
|
|
18
19
|
(() => {
|