shell-dsl 0.0.26 → 0.0.27

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.
@@ -4,11 +4,13 @@ import { expandEscapes } from "./expand-escapes.mjs";
4
4
  import {
5
5
  createFlagParser
6
6
  } from "./flag-parser.mjs";
7
+ import { matchGlob } from "./match-glob.mjs";
7
8
  export {
9
+ matchGlob,
8
10
  expandEscapes,
9
11
  escapeForInterpolation,
10
12
  escape,
11
13
  createFlagParser
12
14
  };
13
15
 
14
- //# debugId=34A51B2B1E1B7E8664756E2164756E21
16
+ //# debugId=4ED94CE4CB81053364756E2164756E21
@@ -2,9 +2,9 @@
2
2
  "version": 3,
3
3
  "sources": ["../../../../src/utils/index.ts"],
4
4
  "sourcesContent": [
5
- "export { escape, escapeForInterpolation } from \"./escape.mjs\";\nexport { expandEscapes } from \"./expand-escapes.mjs\";\nexport {\n createFlagParser,\n type FlagDefinition,\n type CommandSpec,\n type FlagError,\n type ParseResult,\n type FlagParser,\n} from \"./flag-parser.mjs\";\n"
5
+ "export { escape, escapeForInterpolation } from \"./escape.mjs\";\nexport { expandEscapes } from \"./expand-escapes.mjs\";\nexport {\n createFlagParser,\n type FlagDefinition,\n type CommandSpec,\n type FlagError,\n type ParseResult,\n type FlagParser,\n} from \"./flag-parser.mjs\";\nexport { matchGlob } from \"./match-glob.mjs\";\n"
6
6
  ],
7
- "mappings": ";AAAA;AACA;AACA;AAAA;AAAA;",
8
- "debugId": "34A51B2B1E1B7E8664756E2164756E21",
7
+ "mappings": ";AAAA;AACA;AACA;AAAA;AAAA;AAQA;",
8
+ "debugId": "4ED94CE4CB81053364756E2164756E21",
9
9
  "names": []
10
10
  }
@@ -0,0 +1,62 @@
1
+ // src/utils/match-glob.ts
2
+ function matchGlob(pattern, str, caseInsensitive = false) {
3
+ if (caseInsensitive) {
4
+ pattern = pattern.toLowerCase();
5
+ str = str.toLowerCase();
6
+ }
7
+ let regex = "^";
8
+ for (let i = 0;i < pattern.length; i++) {
9
+ const c = pattern[i];
10
+ switch (c) {
11
+ case "*":
12
+ regex += ".*";
13
+ break;
14
+ case "?":
15
+ regex += ".";
16
+ break;
17
+ case "[": {
18
+ let j = i + 1;
19
+ if (pattern[j] === "!" || pattern[j] === "^")
20
+ j++;
21
+ if (pattern[j] === "]")
22
+ j++;
23
+ while (j < pattern.length && pattern[j] !== "]")
24
+ j++;
25
+ if (j >= pattern.length) {
26
+ regex += "\\[";
27
+ } else {
28
+ let charClass = pattern.slice(i, j + 1);
29
+ charClass = charClass.replace(/^\[!/, "[^");
30
+ regex += charClass;
31
+ i = j;
32
+ }
33
+ break;
34
+ }
35
+ case ".":
36
+ case "^":
37
+ case "$":
38
+ case "+":
39
+ case "{":
40
+ case "}":
41
+ case "(":
42
+ case ")":
43
+ case "|":
44
+ case "\\":
45
+ regex += "\\" + c;
46
+ break;
47
+ default:
48
+ regex += c;
49
+ }
50
+ }
51
+ regex += "$";
52
+ try {
53
+ return new RegExp(regex).test(str);
54
+ } catch {
55
+ return false;
56
+ }
57
+ }
58
+ export {
59
+ matchGlob
60
+ };
61
+
62
+ //# debugId=BB2D4981D6540D6764756E2164756E21
@@ -0,0 +1,10 @@
1
+ {
2
+ "version": 3,
3
+ "sources": ["../../../../src/utils/match-glob.ts"],
4
+ "sourcesContent": [
5
+ "/**\n * Simple glob pattern matching (fnmatch-style)\n * Supports: * (any chars), ? (single char), [...] (character class)\n */\nexport function matchGlob(pattern: string, str: string, caseInsensitive = false): boolean {\n if (caseInsensitive) {\n pattern = pattern.toLowerCase();\n str = str.toLowerCase();\n }\n\n // Convert glob to regex\n let regex = \"^\";\n for (let i = 0; i < pattern.length; i++) {\n const c = pattern[i]!;\n switch (c) {\n case \"*\":\n regex += \".*\";\n break;\n case \"?\":\n regex += \".\";\n break;\n case \"[\": {\n // Find closing bracket\n let j = i + 1;\n // Handle negation\n if (pattern[j] === \"!\" || pattern[j] === \"^\") j++;\n // Handle ] as first char in class\n if (pattern[j] === \"]\") j++;\n while (j < pattern.length && pattern[j] !== \"]\") j++;\n if (j >= pattern.length) {\n // No closing bracket, treat [ as literal\n regex += \"\\\\[\";\n } else {\n let charClass = pattern.slice(i, j + 1);\n // Convert ! to ^ for negation in regex\n charClass = charClass.replace(/^\\[!/, \"[^\");\n regex += charClass;\n i = j;\n }\n break;\n }\n case \".\":\n case \"^\":\n case \"$\":\n case \"+\":\n case \"{\":\n case \"}\":\n case \"(\":\n case \")\":\n case \"|\":\n case \"\\\\\":\n regex += \"\\\\\" + c;\n break;\n default:\n regex += c;\n }\n }\n regex += \"$\";\n\n try {\n return new RegExp(regex).test(str);\n } catch {\n return false;\n }\n}\n"
6
+ ],
7
+ "mappings": ";AAIO,SAAS,SAAS,CAAC,SAAiB,KAAa,kBAAkB,OAAgB;AAAA,EACxF,IAAI,iBAAiB;AAAA,IACnB,UAAU,QAAQ,YAAY;AAAA,IAC9B,MAAM,IAAI,YAAY;AAAA,EACxB;AAAA,EAGA,IAAI,QAAQ;AAAA,EACZ,SAAS,IAAI,EAAG,IAAI,QAAQ,QAAQ,KAAK;AAAA,IACvC,MAAM,IAAI,QAAQ;AAAA,IAClB,QAAQ;AAAA,WACD;AAAA,QACH,SAAS;AAAA,QACT;AAAA,WACG;AAAA,QACH,SAAS;AAAA,QACT;AAAA,WACG,KAAK;AAAA,QAER,IAAI,IAAI,IAAI;AAAA,QAEZ,IAAI,QAAQ,OAAO,OAAO,QAAQ,OAAO;AAAA,UAAK;AAAA,QAE9C,IAAI,QAAQ,OAAO;AAAA,UAAK;AAAA,QACxB,OAAO,IAAI,QAAQ,UAAU,QAAQ,OAAO;AAAA,UAAK;AAAA,QACjD,IAAI,KAAK,QAAQ,QAAQ;AAAA,UAEvB,SAAS;AAAA,QACX,EAAO;AAAA,UACL,IAAI,YAAY,QAAQ,MAAM,GAAG,IAAI,CAAC;AAAA,UAEtC,YAAY,UAAU,QAAQ,QAAQ,IAAI;AAAA,UAC1C,SAAS;AAAA,UACT,IAAI;AAAA;AAAA,QAEN;AAAA,MACF;AAAA,WACK;AAAA,WACA;AAAA,WACA;AAAA,WACA;AAAA,WACA;AAAA,WACA;AAAA,WACA;AAAA,WACA;AAAA,WACA;AAAA,WACA;AAAA,QACH,SAAS,OAAO;AAAA,QAChB;AAAA;AAAA,QAEA,SAAS;AAAA;AAAA,EAEf;AAAA,EACA,SAAS;AAAA,EAET,IAAI;AAAA,IACF,OAAO,IAAI,OAAO,KAAK,EAAE,KAAK,GAAG;AAAA,IACjC,MAAM;AAAA,IACN,OAAO;AAAA;AAAA;",
8
+ "debugId": "BB2D4981D6540D6764756E2164756E21",
9
+ "names": []
10
+ }
@@ -1,3 +1,4 @@
1
1
  export { escape, escapeForInterpolation } from "./escape.ts";
2
2
  export { expandEscapes } from "./expand-escapes.ts";
3
3
  export { createFlagParser, type FlagDefinition, type CommandSpec, type FlagError, type ParseResult, type FlagParser, } from "./flag-parser.ts";
4
+ export { matchGlob } from "./match-glob.ts";
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Simple glob pattern matching (fnmatch-style)
3
+ * Supports: * (any chars), ? (single char), [...] (character class)
4
+ */
5
+ export declare function matchGlob(pattern: string, str: string, caseInsensitive?: boolean): boolean;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "shell-dsl",
3
- "version": "0.0.26",
3
+ "version": "0.0.27",
4
4
  "description": "A sandboxed shell-style DSL for running scriptable command pipelines in-process without host OS access",
5
5
  "author": "ricsam <oss@ricsam.dev>",
6
6
  "license": "MIT",