mirror of
https://gitee.com/nocobase/nocobase.git
synced 2025-05-09 07:29:24 +08:00
feat: refactor variable extraction logic to use extractTemplateVariable function
This commit is contained in:
parent
469d6819ab
commit
fd8784eee5
@ -6,7 +6,7 @@
|
||||
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
||||
* For more information, please refer to: https://www.nocobase.com/agreement.
|
||||
*/
|
||||
|
||||
import { extractTemplateVariable } from '@nocobase/json-template-parser';
|
||||
import { REGEX_OF_VARIABLE } from './isVariable';
|
||||
|
||||
/**
|
||||
@ -20,6 +20,6 @@ export const getPath = (variableString: string) => {
|
||||
return variableString;
|
||||
}
|
||||
|
||||
const matches = variableString.match(REGEX_OF_VARIABLE);
|
||||
return matches[0].replace(REGEX_OF_VARIABLE, '$1');
|
||||
const variable = extractTemplateVariable(variableString);
|
||||
return variable;
|
||||
};
|
||||
|
@ -6,6 +6,7 @@
|
||||
* This project is dual-licensed under AGPL-3.0 and NocoBase Commercial License.
|
||||
* For more information, please refer to: https://www.nocobase.com/agreement.
|
||||
*/
|
||||
import { extractTemplateVariable } from '@nocobase/json-template-parser';
|
||||
|
||||
export const REGEX_OF_VARIABLE = /^\s*\{\{\s*([a-zA-Z0-9_$-.]+?)\s*\}\}\s*$/g;
|
||||
export const REGEX_OF_VARIABLE_IN_EXPRESSION = /\{\{\s*([a-zA-Z0-9_$-.]+?)\s*\}\}/g;
|
||||
@ -14,12 +15,11 @@ export const isVariable = (str: unknown) => {
|
||||
if (typeof str !== 'string') {
|
||||
return false;
|
||||
}
|
||||
const matches = str.match(REGEX_OF_VARIABLE);
|
||||
const variable = extractTemplateVariable(str);
|
||||
|
||||
if (!matches) {
|
||||
if (!variable) {
|
||||
return false;
|
||||
}
|
||||
|
||||
return true;
|
||||
};
|
||||
|
||||
|
@ -18,9 +18,15 @@ type Filter = {
|
||||
args: string[];
|
||||
};
|
||||
|
||||
export function extractTemplateVariable(template: string) {
|
||||
const escapedTemplate = escape(template ?? '');
|
||||
const fullVariable = engine.fullVariablesSync(escapedTemplate)[0] ?? '';
|
||||
return revertEscape(fullVariable);
|
||||
}
|
||||
|
||||
export function extractTemplateElements(template: string) {
|
||||
const escapedTemplate = escape(template ?? '');
|
||||
const fullVariable = engine.fullVariablesSync(escapeSpecialChars(escapedTemplate))[0] ?? '';
|
||||
const fullVariable = engine.fullVariablesSync(escapedTemplate)[0] ?? '';
|
||||
const variableSegments = engine.variableSegmentsSync(escapedTemplate)[0] ?? [];
|
||||
const parsedTemplate = engine.parse(escapedTemplate)[0] ?? {};
|
||||
|
||||
|
Loading…
x
Reference in New Issue
Block a user