-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathutils.ts
More file actions
23 lines (21 loc) · 748 Bytes
/
utils.ts
File metadata and controls
23 lines (21 loc) · 748 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
export type UsecaseType = "user" | "system";
export const splitParameters = (message: string, type: UsecaseType) => {
const regex = type === "user" ? /(\w+:[\w,\\.\-_:]+)+/ : /(\w+:[\w,:\\[\]]+)+/;
const [firstMessage, ...paramsMessage] = message.split(regex);
return {
firstMessage: firstMessage.trim(),
paramsMessage,
};
};
/**
* @params text key:hoge:value1,value2
* return { key: "key:hoge", value: ["value1", "value2"] }
*/
export const extractParams = (text: string, type: UsecaseType) => {
const regex = type === "user" ? /(:[\w,\\.\-_]+$)/ : /(:string\[\]$)/;
const [key, splitedValueString] = text.trim().split(regex, 2);
return {
key: key,
value: splitedValueString.replace(":", "").split(","),
};
};