MCPcopy Create free account
hub / github.com/Azure/static-web-apps-cli / globToRegExp

Function globToRegExp

src/core/utils/glob.ts:10–35  ·  view source on GitHub ↗
(glob: string | undefined)

Source from the content-addressed store, hash-verified

8 * @returns a string containing a valid RegExp
9 */
10export function globToRegExp(glob: string | undefined) {
11 logger.silly(`turning glob expression into valid RegExp`);
12 logger.silly(` - glob: ${chalk.yellow(glob)}`);
13
14 if (!glob) {
15 logger.silly(` - glob is empty, return empty string`);
16 return "";
17 }
18
19 if (glob === "*") {
20 logger.silly(` - glob is ${chalk.yellow("*")}, return ${chalk.yellow(".*")}`);
21 return ".*";
22 }
23
24 const filesExtensionMatch = glob.match(/{.*}/);
25 if (filesExtensionMatch) {
26 const filesExtensionExpression = filesExtensionMatch[0];
27 if (filesExtensionExpression) {
28 // build a regex group (png|jpg|gif)
29 const filesExtensionRegEx = filesExtensionExpression.replace(/\,/g, "|").replace("{", "(").replace("}", ")");
30 glob = glob.replace(filesExtensionExpression, filesExtensionRegEx);
31 }
32 }
33
34 return glob.replace(/\//g, "\\/").replace("*.", ".*").replace("/*", "/.*");
35}
36
37/**
38 * Check if the route rule contains a valid wildcard expression

Callers 3

navigationFallbackFunction · 0.85
glob.spec.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected

Used in the wild real call sites across dependent graphs

searching dependent graphs…