(env: string)
| 21 | * `createDebug` is called many times at startup. |
| 22 | */ |
| 23 | export function parsePatterns(env: string): ParsedPatterns { |
| 24 | if (cached !== undefined && cached.env === env) { |
| 25 | return cached.parsed; |
| 26 | } |
| 27 | |
| 28 | const include: RegExp[] = []; |
| 29 | const exclude: RegExp[] = []; |
| 30 | |
| 31 | for (const raw of env.split(/[\s,]+/)) { |
| 32 | if (raw === "") { |
| 33 | continue; |
| 34 | } |
| 35 | if (raw.startsWith("-")) { |
| 36 | exclude.push(namespaceToRegExp(raw.slice(1))); |
| 37 | } else { |
| 38 | include.push(namespaceToRegExp(raw)); |
| 39 | } |
| 40 | } |
| 41 | |
| 42 | const parsed: ParsedPatterns = { include, exclude }; |
| 43 | cached = { env, parsed }; |
| 44 | return parsed; |
| 45 | } |
| 46 | |
| 47 | /** |
| 48 | * Converts a `DEBUG`-style namespace pattern into an anchored regex. |
no test coverage detected