generated from Himenon/template-esm-js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample.ts
44 lines (38 loc) · 1.01 KB
/
sample.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
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
// pnpm run exec:sample
import { Parser } from "../src/index.js";
const messageParser = new Parser({
messageItems: [
{
command: "ping",
description: "ping",
},
{
command: "get release tags:string[]",
description: "Get Release By Tags",
},
],
});
const showParsedValue = (message: string) => {
const parsedValue = messageParser.parse(message);
if (parsedValue.kind === "plain") {
console.log({
message: parsedValue.message,
});
} else if (parsedValue.kind === "command") {
console.log({
action: parsedValue.action,
actionTargets: parsedValue.actionTargets,
parameters: parsedValue.parameters || {},
});
}
};
showParsedValue("get release tags:v1.0.0,v1.1.0");
// {
// action: 'get',
// actionTargets: [ 'release' ],
// parameters: { tags: [ 'v1.0.0', 'v1.1.0' ] }
// }
showParsedValue("ping");
// { action: 'ping', actionTargets: [], parameters: {} }
showParsedValue("unregistered command");
// { message: 'unregistered command' }