command-cmd 1.0.0

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.
Files changed (2) hide show
  1. package/cmd.js +57 -0
  2. package/package.json +12 -0
package/cmd.js ADDED
@@ -0,0 +1,57 @@
1
+ export function cmd(message) {
2
+ if (typeof message !== 'string') {
3
+ return [];
4
+ }
5
+
6
+ const results = [];
7
+ const regex = /\[([^[\]]+?)\]/g;
8
+ let match;
9
+
10
+ while ((match = regex.exec(message)) !== null) {
11
+ const inside = match[1].trim();
12
+ if (!inside) continue;
13
+
14
+ const obj = { type: undefined, command: undefined, extra: undefined };
15
+
16
+ const parts = inside.split(',');
17
+
18
+ for (const rawPart of parts) {
19
+ const part = rawPart.trim();
20
+ if (!part) continue;
21
+
22
+ const [rawKey, ...rest] = part.split(':');
23
+ if (!rawKey || rest.length === 0) continue;
24
+
25
+ const key = rawKey.trim().toLowerCase();
26
+ const value = rest.join(':').trim();
27
+ if (!value) continue;
28
+
29
+ if (key === 'type' || key === 'tipo') {
30
+ obj.type = value;
31
+ } else if (key === 'command' || key === 'comando') {
32
+ obj.command = value;
33
+ } else if (key === 'extra') {
34
+ obj.extra = value;
35
+ } else if (!obj.type) {
36
+ obj.type = rawKey.trim();
37
+ obj.command = value;
38
+ } else if (!obj.command) {
39
+ obj.command = value;
40
+ } else if (!obj.extra) {
41
+ obj.extra = value;
42
+ }
43
+ }
44
+
45
+ if (obj.type && obj.command) {
46
+ results.push(obj);
47
+ }
48
+ }
49
+
50
+ return results;
51
+ }
52
+
53
+ export function extractFirstCommand(message) {
54
+ const [first] = cmd(message);
55
+ return first || null;
56
+ }
57
+
package/package.json ADDED
@@ -0,0 +1,12 @@
1
+ {
2
+ "name": "command-cmd",
3
+ "version": "1.0.0",
4
+ "main": "cmd.js",
5
+ "scripts": {
6
+ "test": "echo \"Error: no test specified\" && exit 1"
7
+ },
8
+ "keywords": [],
9
+ "author": "cmstudio",
10
+ "license": "ISC",
11
+ "description": "Extraia comandos, ótimo para usar com agentes de IA"
12
+ }