MCPcopy Create free account
hub / github.com/cloudflare/computer / splitGlobPattern

Function splitGlobPattern

packages/computer/src/workspace.ts:1241–1251  ·  view source on GitHub ↗
(pattern: string)

Source from the content-addressed store, hash-verified

1239}
1240
1241function splitGlobPattern(pattern: string): { directory: string; relativePattern?: string } {
1242 const normalized = pattern.startsWith("/") ? pattern : `/workspace/${pattern}`;
1243 const wildcard = firstWildcardIndex(normalized);
1244 if (wildcard === -1) {
1245 return { directory: dirname(normalized), relativePattern: basename(normalized) };
1246 }
1247 const slash = normalized.lastIndexOf("/", wildcard);
1248 const directory = slash <= 0 ? "/" : normalized.slice(0, slash);
1249 const relativePattern = normalized.slice(slash + 1);
1250 return { directory, relativePattern };
1251}
1252
1253function firstWildcardIndex(pattern: string): number {
1254 const star = pattern.indexOf("*");

Callers 1

globFunction · 0.85

Calls 3

firstWildcardIndexFunction · 0.85
dirnameFunction · 0.70
basenameFunction · 0.70

Tested by

no test coverage detected