(glob: string | undefined)
| 8 | * @returns a string containing a valid RegExp |
| 9 | */ |
| 10 | export 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 |
no outgoing calls
no test coverage detected
searching dependent graphs…