-
Notifications
You must be signed in to change notification settings - Fork 0
/
actions.ts
29 lines (22 loc) · 845 Bytes
/
actions.ts
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
export function extractActions(text: string) {
const actions: Array<{ action: string; parameters: any }> = [];
const actionRegex = /<Action\s+name="([^"]+)">(.*?)<\/Action>/gs;
let match;
while ((match = actionRegex.exec(text)) !== null) {
const actionName = match[1];
const actionContent = match[2];
const action: { action: string; parameters: any } = {
action: actionName,
parameters: {},
};
const parameterRegex = /<Parameter\s+name="([^"]+)">(.*?)<\/Parameter>/gs;
let parameterMatch;
while ((parameterMatch = parameterRegex.exec(actionContent)) !== null) {
const paramName = parameterMatch[1];
const paramValue = parameterMatch[2];
action.parameters[paramName] = paramValue.trim();
}
actions.push(action);
}
return actions;
}